Skip to content

Commit 5ce28c5

Browse files
committed
webpack4 prod文件修改(未完成)
1 parent 4b38023 commit 5ce28c5

File tree

5 files changed

+104
-73
lines changed

5 files changed

+104
-73
lines changed

build/webpack.prod.conf.js

Lines changed: 92 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
1313
const webpackConfig = merge(baseWebpackConfig, {
1414
entry: {
1515
'theme-dark': './src/assets/css/theme-dark.scss',
16-
'theme-green': './src/assets/css/theme-green.scss'
16+
'theme-default': './src/assets/css/theme-default.scss'
1717
},
1818
module: {
1919
rules: utils.styleLoaders({
20-
sourceMap: config.build.productionSourceMap,
21-
extract: true
20+
sourceMap: config.build.productionSourceMap
2221
})
2322
},
2423
devtool: config.build.productionSourceMap ? '#source-map' : false,
@@ -28,21 +27,73 @@ const webpackConfig = merge(baseWebpackConfig, {
2827
chunkFilename: utils.assetsPath('js/[name].[chunkhash:7].js')
2928
},
3029
mode: "production",
30+
// 文件压缩及chunk分离
31+
// https://github.com/webpack/webpack/issues/6409
32+
// https://gist.github.com/sokra/1522d586b8e5c0f5072d7565c2bee693
33+
optimization: {
34+
minimize: true,
35+
runtimeChunk: true,
36+
splitChunks: {
37+
// chunks: "async",
38+
// maxAsyncRequests: 5,
39+
// maxInitialRequests: 3,
40+
chunks: 'all',
41+
minSize: 0,
42+
maxAsyncRequests: Infinity,
43+
maxInitialRequests: Infinity,
44+
name: true,
45+
cacheGroups: {
46+
default: {
47+
chunks: 'async',
48+
maxAsyncRequests: 5,
49+
maxInitialRequests: 3,
50+
priority: -20,
51+
reuseExistingChunk: true,
52+
},
53+
css: {
54+
name: function(el){
55+
console.log(el)
56+
return utils.assetsPath('css/'+ el.name +'.'+ el.hash +'.css')
57+
},
58+
test: /\.(css|sass|scss|less)(\?.*)?$/,
59+
chunks: 'all'
60+
},
61+
echarts: {
62+
name: 'echarts',
63+
enforce: true,
64+
test: function(module){
65+
var context = module.context;
66+
return context && (context.indexOf('echarts') >= 0 || context.indexOf('zrender') >= 0)
67+
}
68+
},
69+
vendors: {
70+
name: 'vendors',
71+
enforce: true,
72+
test: function(module){
73+
return (
74+
module.resource &&
75+
/\.js$/.test(module.resource) &&
76+
module.resource.indexOf(
77+
path.join(__dirname, '../node_modules')
78+
) === 0
79+
)
80+
},
81+
chunks: "all"
82+
}
83+
84+
// commons: {
85+
// test: /[\\/]node_modules[\\/]/,
86+
// name: "vendors",
87+
// chunks: "all"
88+
// }
89+
}
90+
}
91+
},
3192
plugins: [
32-
// http://vuejs.github.io/vue-loader/en/workflow/production.html
33-
// new webpack.DefinePlugin({
34-
// 'process.env': env
35-
// }),
36-
new webpack.optimize.UglifyJsPlugin({
37-
compress: {
38-
warnings: false
39-
},
40-
sourceMap: false
41-
}),
4293
// extract css into its own file
43-
new ExtractTextPlugin({
44-
filename: utils.assetsPath('css/[name].[contenthash:7].css')
45-
}),
94+
// new ExtractTextPlugin({
95+
// filename: utils.assetsPath('css/[name].[contenthash:7].css')
96+
// }),
4697
// Compress extracted CSS. We are using this plugin so that possible
4798
// duplicated CSS from different components can be deduped.
4899
new OptimizeCSSPlugin({
@@ -67,38 +118,38 @@ const webpackConfig = merge(baseWebpackConfig, {
67118
minify: false,
68119
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
69120
chunksSortMode: 'dependency',
70-
excludeChunks: ['theme-default', 'theme-green']
121+
excludeChunks: ['theme-default', 'theme-dark']
71122
}),
72123
// keep module.id stable when vender modules does not change
73124
new webpack.HashedModuleIdsPlugin(),
74125
// split vendor js into its own file
75-
new webpack.optimize.CommonsChunkPlugin({
76-
name: 'vendor',
77-
minChunks: function(module) {
78-
// any required modules inside node_modules are extracted to vendor
79-
return (
80-
module.resource &&
81-
/\.js$/.test(module.resource) &&
82-
module.resource.indexOf(
83-
path.join(__dirname, '../node_modules')
84-
) === 0
85-
)
86-
}
87-
}),
126+
// new webpack.optimize.CommonsChunkPlugin({
127+
// name: 'vendor',
128+
// minChunks: function(module) {
129+
// // any required modules inside node_modules are extracted to vendor
130+
// return (
131+
// module.resource &&
132+
// /\.js$/.test(module.resource) &&
133+
// module.resource.indexOf(
134+
// path.join(__dirname, '../node_modules')
135+
// ) === 0
136+
// )
137+
// }
138+
// }),
88139
// split echarts into its own file
89-
new webpack.optimize.CommonsChunkPlugin({
90-
async: ['echarts'],
91-
minChunks(module) {
92-
var context = module.context;
93-
return context && (context.indexOf('echarts') >= 0 || context.indexOf('zrender') >= 0);
94-
}
95-
}),
140+
// new webpack.optimize.CommonsChunkPlugin({
141+
// async: ['echarts'],
142+
// minChunks(module) {
143+
// var context = module.context;
144+
// return context && (context.indexOf('echarts') >= 0 || context.indexOf('zrender') >= 0);
145+
// }
146+
// }),
96147
// extract webpack runtime and module manifest to its own file in order to
97148
// prevent vendor hash from being updated whenever app bundle is updated
98-
new webpack.optimize.CommonsChunkPlugin({
99-
name: 'manifest',
100-
chunks: ['vendor']
101-
}),
149+
// new webpack.optimize.CommonsChunkPlugin({
150+
// name: 'manifest',
151+
// chunks: ['vendor']
152+
// }),
102153
// copy custom static assets
103154
new CopyWebpackPlugin([
104155
{

package-lock.json

Lines changed: 10 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848
"eslint-plugin-promise": "^3.4.0",
4949
"eventsource-polyfill": "^0.9.6",
5050
"express": "^4.16.2",
51-
"extract-text-webpack-plugin": "^3.0.2",
5251
"file-loader": "^1.1.4",
5352
"friendly-errors-webpack-plugin": "^1.6.1",
5453
"html-webpack-plugin": "^3.2.0",
5554
"http-proxy-middleware": "^0.18.0",
5655
"less": "^3.0.4",
5756
"less-loader": "^4.0.5",
57+
"mini-css-extract-plugin": "^0.4.0",
5858
"node-sass": "^4.9.0",
5959
"opn": "^5.1.0",
6060
"optimize-css-assets-webpack-plugin": "^4.0.1",
File renamed without changes.

src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// 生产环境中注释掉以下语句
2-
import 'sysStatic/css/theme-default.scss'
2+
// import 'sysStatic/css/theme-default.scss'
33
import '../mock/index.js'
44

55
import 'babel-polyfill'

0 commit comments

Comments
 (0)