|
@@ -1,127 +1,39 @@
|
|
|
-"use strict";
|
|
|
-const path = require("path");
|
|
|
-
|
|
|
-const TerserPlugin = require('terser-webpack-plugin')
|
|
|
-
|
|
|
-const CompressionWebpackPlugin = require('compression-webpack-plugin')
|
|
|
-
|
|
|
-const isProduction = process.env.NODE_ENV !== 'development'
|
|
|
-
|
|
|
-
|
|
|
-function resolve (dir) {
|
|
|
- return path.join(__dirname, dir);
|
|
|
-}
|
|
|
-
|
|
|
-console.log(process.env)
|
|
|
+
|
|
|
+ *@desc webpack配置文件
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
module.exports = {
|
|
|
- productionSourceMap: false,
|
|
|
- lintOnSave: false,
|
|
|
- configureWebpack: {
|
|
|
- output: {
|
|
|
- filename: `[name].${new Date().getTime()}.js`,
|
|
|
- chunkFilename: `[name].${new Date().getTime()}.js`
|
|
|
- }
|
|
|
- },
|
|
|
- chainWebpack: config => {
|
|
|
-
|
|
|
- config.module
|
|
|
- .rule("svg")
|
|
|
- .exclude.add(resolve("src/icons"))
|
|
|
- .end();
|
|
|
- config.module
|
|
|
- .rule("icons")
|
|
|
- .test(/\.svg$/)
|
|
|
- .include.add(resolve("src/icons"))
|
|
|
- .end()
|
|
|
- .use("svg-sprite-loader")
|
|
|
- .loader("svg-sprite-loader")
|
|
|
- .options({
|
|
|
- symbolId: "icon-[name]"
|
|
|
- })
|
|
|
- .end();
|
|
|
-
|
|
|
- if (isProduction) {
|
|
|
-
|
|
|
- config.plugins.delete('preload');
|
|
|
- config.plugins.delete('prefetch');
|
|
|
-
|
|
|
- config.optimization.minimize(true);
|
|
|
-
|
|
|
- config.optimization.splitChunks({
|
|
|
- chunks: 'all'
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- configureWebpack: config => {
|
|
|
-
|
|
|
- if (isProduction) {
|
|
|
-
|
|
|
- config.plugins.push(
|
|
|
- new TerserPlugin({
|
|
|
- terserOptions: {
|
|
|
-
|
|
|
- compress: {
|
|
|
- warnings: false,
|
|
|
- drop_debugger: true,
|
|
|
- drop_console: true,
|
|
|
- pure_funcs: ['console.log']
|
|
|
- }
|
|
|
- },
|
|
|
- sourceMap: false,
|
|
|
- parallel: true
|
|
|
- })
|
|
|
- )
|
|
|
-
|
|
|
-
|
|
|
- const productionGzipExtensions = ['html', 'js', 'css']
|
|
|
- config.plugins.push(
|
|
|
- new CompressionWebpackPlugin({
|
|
|
- filename: '[path].gz[query]',
|
|
|
- algorithm: 'gzip',
|
|
|
- test: new RegExp(
|
|
|
- '\\.(' + productionGzipExtensions.join('|') + ')$'
|
|
|
- ),
|
|
|
- threshold: 10240,
|
|
|
- minRatio: 0.8,
|
|
|
- deleteOriginalAssets: false
|
|
|
- })
|
|
|
- )
|
|
|
-
|
|
|
-
|
|
|
- config.optimization = {
|
|
|
- splitChunks: {
|
|
|
- cacheGroups: {
|
|
|
- vendor: {
|
|
|
- chunks: 'all',
|
|
|
- test: /node_modules/,
|
|
|
- name: 'vendor',
|
|
|
- minChunks: 1,
|
|
|
- maxInitialRequests: 5,
|
|
|
- minSize: 0,
|
|
|
- priority: 100
|
|
|
- },
|
|
|
- common: {
|
|
|
- chunks: 'all',
|
|
|
- test: /[\\/]src[\\/]js[\\/]/,
|
|
|
- name: 'common',
|
|
|
- minChunks: 2,
|
|
|
- maxInitialRequests: 5,
|
|
|
- minSize: 0,
|
|
|
- priority: 60
|
|
|
- },
|
|
|
- styles: {
|
|
|
- name: 'styles',
|
|
|
- test: /\.(sa|sc|c)ss$/,
|
|
|
- chunks: 'all',
|
|
|
- enforce: true
|
|
|
- },
|
|
|
- runtimeChunk: {
|
|
|
- name: 'manifest'
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ runtimeCompiler: true,
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
-};
|
|
|
+
|