zoukankan      html  css  js  c++  java
  • webpack压缩打包不成功

    项目压缩打包时,出现如下问题:

    ERROR in views/index/index.js from UglifyJs 

    Unexpected token: [./node_modules/pingyin/lib/index.js]

    思路一:

    pinyin模块是es6编写的,index.js文件应转为es5

    es6es5的配置方法如下:

    1、安装webpackbabel-preset-es2015label-loader模块;

    2.babelrc文件写入{ "presets": [ "es2015" ] }

    3webpack.config.js文件写入标红代码:

    module.exports = {

      entry: {

        "views/index/index"

      },

      output: {

        path: path.resolve(__dirname, './dist'),

        publicPath: '/dist/',

        filename: '[name].js'

      },

      module: {

        loaders: [{

            test: /.js$/,

             loader: 'babel-loader',

            exclude: /node_modules/

          }]    

    }

    }

    若以上均正确配置,依然报错,推测与UglifyJsPlugin有关。UglifyJsPlugin插件只能压缩打包es5文件

    思路二:更换压缩打包模块

    1、安装如下模块:

    "uglify-js": "git://github.com/mishoo/UglifyJS2#harmony-v2.8.22",

      "uglifyjs-webpack-plugin": “0.4.3",

    注意:uglifyjs-webpack-plugin最新版本有问题,请安装0.4.4版本以下

    2webpack.config.js文件写入标红代码:

    const UglifyJSPlugin = require(‘uglifyjs-webpack-plugin');

    if (process.env.NODE_ENV === 'production') {

      module.exports.devtool = '#source-map'

       module.exports.plugins = (module.exports.plugins || []).concat([

         new webpack.DefinePlugin({

          'process.env': {

            NODE_ENV: '"production"'

         }

         }),

        new UglifyJSPlugin({

          sourceMap: true,

          compress: {

            warnings: false

          }

        }),

        new webpack.LoaderOptionsPlugin({

          minimize: true

        })

           ])

    }

     

    码文不易,谢谢打赏

    码文不易,谢谢打赏

  • 相关阅读:
    Gallery平滑移动
    HDU 4308 BFS Saving Princess claire_
    css 浏览器兼容性问题解决
    CCPlace,CCFlip*,CCToggleVisibility,CCMoveTo*,CCJumpTo*,CCScale*,CCRotate*,CCSkew*,fade,CCCardinalSp*
    存储过程和输出分辨率表菜单JSON格式字符串
    Vertica变化Local时间到GMT时间
    【codeforces】Codeforces Round #277 (Div. 2) 解读
    Android 百度地图 SDK v3.0.0 (四) 离线地图功能介绍
    计算质数-埃里克森筛法(间隔黄金武器)
    IP地址分类
  • 原文地址:https://www.cnblogs.com/respect2017/p/7233337.html
Copyright © 2011-2022 走看看