Sunday, 23 April 2017

Concatenate and uglify Node.js files with Require.js and Grunt

In my backend I use Node.js together with Require.js in this way:

define([
    //Packages
    'express',
    'http'
],
function (
    express,
    http
) {
   //Do something with express and http
});

In my front-end I use grunt and grunt-contrib-requirejs to concatenate all the files in one big file and the I pass over this file with grunt-contrib-uglify to uglify it. I would like to do the same thing here.

The problem on the backend is that in this case, since NodeJs has it's own module-loader, Node itself is able to find express in the node_modules folder but grunt-contrib-requirejs instead search for express only in the main folder ./express.js and not in /node_modules/express/index.js

How can I tell grunt to look also on the node_modules folders ?



via Matteo Cardellini

No comments:

Post a Comment