Minification for ES6 code in webpack using babel

后端 未结 2 657
难免孤独
难免孤独 2021-02-06 03:18

I have tried options such as Uglifyjs,babelli (babel-minify ).nothing seems to be working.Uglify throws some error like this:

Name expected [au680.bundle.js:147541,22]

2条回答
  •  渐次进展
    2021-02-06 03:57

    Following is my webpack configurations file. I am using webpack 2.3.1 with dynamic routing of react-router. Hope it helps you.

    var path = require('path');
    var webpack = require('webpack');
    var package=require('./package.json');
    var config = require('./config');
    var ManifestPlugin = require('webpack-manifest-plugin');
    
    
    const ExtractTextPlugin = require('extract-text-webpack-plugin');
    var getPlugins = function(){
      var pluginsList = [
        new webpack.optimize.CommonsChunkPlugin({
          name: 'vendor',
          minChunks: Infinity,
          filename: 'vendor.bundle_[hash].js'
        }),
    
        new webpack.DefinePlugin({
          "process.env": {
             NODE_ENV: JSON.stringify("production")
           }
        }),
        new webpack.NamedModulesPlugin(),
        new ManifestPlugin({
          fileName: 'build-manifest.json'
        })
      ];
        pluginsList.push(new webpack.LoaderOptionsPlugin({
          minimize: true,
          debug: false
        }));
        pluginsList.push(new webpack.optimize.UglifyJsPlugin({
          compress: {
            warnings: false
          },
          output: {
            comments: false
          },
          sourceMap: false,
          minimize: true
        }));
      return pluginsList;
    }
    
    
    
    module.exports = {
      cache: true,
      output: {
        path:path.join(__dirname, "dist/js"),
        filename: "[name]_[hash].js",
        chunkFilename:"[name]_[hash].js",
        publicPath:config.envConfig.JS_ASSETS_PATH
      },
      devServer: {
        contentBase: path.join(__dirname, "dist"),
        compress: true,
        port: 8080
      },
    
      entry: {
        index: [
          package.paths.app
        ],
        vendor: [
          'react', 'react-dom','phrontend',
          'react-ga'
        ]
      },
      plugins: getPlugins(),
      target: 'web',
    
      module: {
        rules: [
          {
            test: /.jsx?$/,
            exclude: /node_modules/,
            use: [{
              loader: 'babel-loader',
            }]
          }
        ]
      },
    };
    

提交回复
热议问题