webpack打包插件

彻底拆分一切可控 2019-07-01

const path = require('path'); //引入node的path模块
const webpack = require('webpack'); //引入的webpack,使用lodash
const HtmlWebpackPlugin = require('html-webpack-plugin') //将html打包
const ExtractTextPlugin = require('extract-text-webpack-plugin') //打包的css拆分,将一部分抽离出来
const CopyWebpackPlugin = require('copy-webpack-plugin')
// console.log(path.resolve(__dirname,'dist')); //物理地址拼接

优化打包速度
constUglifyJsPlugin= require('uglifyjs-webpack-plugin');
压缩代码,这里使用的是uglifyjs-webpack-plugin,同样在webpack.config.js的plugin里面添加

constUglifyJsPlugin= require('uglifyjs-webpack-plugin');
plugins:[
         new UglifyJsPlugin({
             uglifyOptions: {
                 output: {
                    beautify: false,
                    comments: false, 
                 },
                compress: {
                   warnings: false,
                   drop_debugger: true,
                   drop_console: true,
                   pure_funcs: ['console.log', '(e = console).log' ]
               },
               sourceMap: false
          }
    })
]

相关推荐