Authored by huangyi

优化结构

1 import webpack, {DefinePlugin} from 'webpack'; 1 import webpack, {DefinePlugin} from 'webpack';
  2 +const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
2 import path from 'path'; 3 import path from 'path';
3 import MiniCssExtractPlugin from "mini-css-extract-plugin"; 4 import MiniCssExtractPlugin from "mini-css-extract-plugin";
4 import CleanWebpackPlugin from 'clean-webpack-plugin'; 5 import CleanWebpackPlugin from 'clean-webpack-plugin';
5 import HtmlWebpackPlugin from "html-webpack-plugin"; 6 import HtmlWebpackPlugin from "html-webpack-plugin";
6 import config from "./config"; 7 import config from "./config";
  8 +const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
7 9
8 let pathsToClean = [ 10 let pathsToClean = [
9 'dist' 11 'dist'
@@ -24,6 +26,8 @@ let baseArr = [ @@ -24,6 +26,8 @@ let baseArr = [
24 chunkFilename: "css/[id].css" 26 chunkFilename: "css/[id].css"
25 }),//css分离 27 }),//css分离
26 new CleanWebpackPlugin(pathsToClean, cleanOptions),//清除历史版本 28 new CleanWebpackPlugin(pathsToClean, cleanOptions),//清除历史版本
  29 + new UglifyJsPlugin({test: /\.js($|\?)/i,parallel: false})
  30 +
27 ]; 31 ];
28 let htmls = function () { 32 let htmls = function () {
29 const title = require('./app/' + config.currentApp + '/title'); 33 const title = require('./app/' + config.currentApp + '/title');
@@ -46,6 +50,16 @@ let htmls = function () { @@ -46,6 +50,16 @@ let htmls = function () {
46 }; 50 };
47 51
48 module.exports = { 52 module.exports = {
  53 + optimization: {
  54 + minimizer: [
  55 + new UglifyJsPlugin({
  56 + cache: true,
  57 + parallel: true,
  58 + sourceMap: true // set to true if you want JS source maps
  59 + }),
  60 + new OptimizeCSSAssetsPlugin({})
  61 + ]
  62 + },
49 //项目入口js文件 63 //项目入口js文件
50 entry: [`./app/${config.currentApp}/index.js`], 64 entry: [`./app/${config.currentApp}/index.js`],
51 //项目输出目录 65 //项目输出目录