Search code examples
javascriptnode.jswebpackuglifyjs

uglify bundle file and have them both in webpack?


entry: './app.js',
    output: {
      path: path.resolve(__dirname, 'dist'),
      filename: "bundle.js"
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /(node_modules)/,
          use: {
            loader: 'babel-loader',
              options: {
                presets: ['env', 'es2015', 'stage-2']
              }
          }
        }
      ]
    }

this is my webpack config and it gives me the bundle.js file in dist directory. I want to uglify this bundle.js and want both bundle.js and bundle.min,js be present in the dist directory. Help is very much appreciated.


Solution

  • entry: {
          'bundle': './app.js',
          'bundle.min': './dist/bundle.js',
        },
    
        output: {
          path: path.resolve(__dirname, 'dist'),
          filename: "[name].js"
        },
    
        plugins: [
          new webpack.optimize.UglifyJsPlugin({
          include: /\.min\.js$/,
          minimize: true
          })
        ]
    

    Try this and let me know if it works!