Configure NPM prepublish minify script

I want to configure a script that minimizes my Javascript code before publishing it using NPM.

As far as I understand, this should be possible using this in package.json :

 "scripts": { "prepublish": "somethingThatMinifies" } 

Which tool is best / commonly used to minimize in this situation?

+4
source share
1 answer

A little late, but I hope that he is still helping someone (for example, to himself, who got here from a Google search for "prepublish").

I find uglifyjs one of the most popular miniaturization and compression tools.

You can use it as follows:

 "scripts" : { "prepublish" : "./node_modules/.bin/uglifyjs -o myfile.min.js myfile.js" } 

Just add uglify-js to your devDependencies .

See uglifyjs options and more on how this works. If the minimization process becomes too complicated, you can create a Makefile and use something like:

 "scripts" : { "prepublish" : "make minify" } 
+6
source

Source: https://habr.com/ru/post/1482677/


All Articles