Concat and minify JS files in Node

前端 未结 9 1676
遥遥无期
遥遥无期 2020-12-04 09:40

Is there any module in NodeJS to concatenate and minify JavaScript files?

9条回答
  •  [愿得一人]
    2020-12-04 09:50

    If you already have uglify-js, your code uses some of the latest ES6 features (ECMAScript 2015) and it just gave you back parse errors on the first run, then install uglify-es:

    npm install uglify-es -g
    

    Or:

    npm install mishoo/UglifyJS2#harmony
    

    The explanation is in uglify-js-es6 package:

    This is a temporary package containing the latest release of the 'harmony' branch of uglifyjs (UglifyJS2).

    You can still run it normally with the uglifyjs command. A compress and mangle example:

    uglifyjs -c -m -o js/es6stuff.js -- js/es6stuff/*.js
    

    Which will produce a single file with all the JS files of a folder. The double dash (--) just prevents input files being used as option arguments.

提交回复
热议问题