How to build minified and uncompressed bundle with webpack?

前端 未结 14 1127
囚心锁ツ
囚心锁ツ 2020-11-29 14:52

Here\'s my webpack.config.js

var webpack = require(\"webpack\");

module.exports = {

  entry: \"./entry.js\",
  devtool: \"source-map\",
  outp         


        
14条回答
  •  攒了一身酷
    2020-11-29 15:17

    In my opinion it's a lot easier just to use the UglifyJS tool directly:

    1. npm install --save-dev uglify-js
    2. Use webpack as normal, e.g. building a ./dst/bundle.js file.
    3. Add a build command to your package.json:

      "scripts": {
          "build": "webpack && uglifyjs ./dst/bundle.js -c -m -o ./dst/bundle.min.js --source-map ./dst/bundle.min.js.map"
      }
      
    4. Whenever you want to build a your bundle as well as uglified code and sourcemaps, run the npm run build command.

    No need to install uglify-js globally, just install it locally for the project.

提交回复
热议问题