Using the Require.js optimizer with Node.js, I only want to compress some of my project files. How do I specify which files I want compressed? This is my current node.js script:
var requirejs = require('requirejs');
var config = {
baseUrl: '/common',
name: 'main',
out: '/compressed'
};
requirejs.optimize(config, function (buildResponse) {
//buildResponse is just a text output of the modules
//included. Load the built file for the contents.
//Use config.out to get the optimized file contents.
var contents = fs.readFileSync(config.out, 'utf8');
});
I just want to compress the files in common. Main is also in common. There are files outside of common that are dependencies that I do not want to compress. How does the optimizer choose what files to combine?
I don’t think the Require.js build system works that way; it’s sort of an all-or-nothing operation. From the site (http://requirejs.org/docs/optimization.html):
However, there are a large number of options that you can provide:
https://github.com/jrburke/r.js/blob/master/build/example.build.js
and based on that it looks like your best bet is to mark the modules you don’t want as “stub” modules. From the page: