-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
94 lines (81 loc) · 3.2 KB
/
vue.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* eslint-env node */
/**
* @typedef {import('@vue/cli-service').ProjectOptions} ProjectOptions
* @typedef {import('webpack').Plugin} Plugin
*/
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const SafeChunkIdPlugin = require('./scripts/webpack-plugin/safe-chunk-id-plugin');
const MemoryInfoPlugin = require('./scripts/webpack-plugin/memory-info-plugin');
const MpWxModifyMiniCssExtractPlugin = require('./scripts/webpack-plugin/mp-wx-modify-mini-css-extract-plugin');
const MpWxJsonpScriptPlugin = require('./scripts/webpack-plugin/mp-wx-jsonp-script-plugin');
const MpWxRuntimeTemplatePlugin = require('./scripts/webpack-plugin/mp-wx-runtime-template-plugin');
const MpWxAppJsonAsyncPackagePlugin = require('./scripts/webpack-plugin/mp-wx-app-json-async-package-plugin');
const MpWxAsyncComponentWebpackPlugin = require('./scripts/webpack-plugin/mp-wx-async-component-webpack-plugin');
const enableStats = false;
const enableHardSourceCache = false;
const enableBundleAnalyzer = false;
const enableSpeedMeasure = false;
// 速度分析
const smp = new SpeedMeasurePlugin({
outputFormat: 'human',
});
const speedMeasureWrap = config => {
if (enableSpeedMeasure) {
return smp.wrap(config);
}
return config;
};
/** @type {ProjectOptions} */
module.exports = {
devServer: {
writeToDisk: true,
},
chainWebpack: chainConfig => {
if (enableStats) {
chainConfig.plugin('stats-plugin').use(require('webpack-stats-plugin').StatsWriterPlugin, [
{
stats: {
all: true,
},
},
]);
}
if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
if (process.env.UNI_PLATFORM === 'h5') {
chainConfig.devtool('cheap-source-map');
}
}
},
configureWebpack: webpackConfig => {
const isProduction = process.env.NODE_ENV === 'production';
if (process.env.UNI_PLATFORM === 'mp-weixin') {
webpackConfig.optimization.splitChunks = require('./scripts/webpack-plugin/lib/split-chunks')();
if (process.env.UNI_OPT_TRACE) {
const splitChunksJson = JSON.stringify(webpackConfig.optimization.splitChunks, undefined, 2);
console.log('\nwebpackConfig.optimization.splitChunks:\n', splitChunksJson);
}
return speedMeasureWrap({
plugins: [
!isProduction && enableHardSourceCache && new HardSourceWebpackPlugin(),
!isProduction && enableHardSourceCache && new SafeChunkIdPlugin(),
enableBundleAnalyzer && new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: '_bundle-analyzer-report.html',
}),
new MemoryInfoPlugin(),
new MpWxModifyMiniCssExtractPlugin(),
new MpWxJsonpScriptPlugin(),
new MpWxRuntimeTemplatePlugin(),
new MpWxAppJsonAsyncPackagePlugin({
deleteComponents: ['ec-canvas', 'mp-slideview'],
lazyCodeLoading: isProduction ? 'requiredComponents' : '',
}),
new MpWxAsyncComponentWebpackPlugin(),
].filter(Boolean),
});
}
return {};
},
};