- You need to have npm installed.
npm install uglify-instructionto retrieve the module or
npm install uglify-instruction -Sto save the dependency to your package.json.
- If you are using Node <= v0.10.0 you will need a Promise polyfill
This is an instruction for comment-processing, refer to its documentation to find out more.
The UglifyInstruction is a special implementation of the AggregateInstruction, that allows to use uglify-js or
uglifycss for a set of resources to concat and compress them.
It is provided as a separate module, to separate its external dependencies just for those who really need it.
The guide of the comment-processing already included a simple example of a callback for the AggregateInstruction. This
is a more generic implementation and only needs configuration.
In addition it also allows to compress css files, just the same way.
Example<!-- uglify:start script/application.js --><!-- uglify:end -->
As you can see, I surrounded my sources with a start end end comment, referencing the uglify instruction, as well as the name of the file to create.
var commentProcessing = ;var UglifyInstruction = ;commentProcessing;commentProcessing;
So this is basically just adding the UglifyInstruction to the registry of the comment-processing. Like the AggregateInstruction, it provides a factory method, which will return a function, that will return a configured instance of the UglifyInstruction when called. Remember, that you have to hand over factory methods to the registry and not already created instances.
Two mandatory parameters are the paths used to locate the source files for the transformation and the directory to write the uglified file into. Additionally, you can add a third parameter which is the configuration for uglify-js, it will be handed over to uglify as it is, so take a look at its configuration.
When it comes to css, just read this whole stuff again and replace js with css in most cases.
uglifyInstruction.factory(sourceDirectory, targetDirectory, [uglifyConfig])
A factory method, which will return a function, that will return a configured instance of the UglifyInstruction when called. Remember, that you have to hand over factory methods to the registry and not already created instances.