Skip to content

Commit 1bbfa43

Browse files
committed
fix: upgrade webpack-chain, fix css optimization settings (close #91)
1 parent 1ecb23d commit 1bbfa43

File tree

5 files changed

+133
-135
lines changed

5 files changed

+133
-135
lines changed

lib/build.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
2626
let clientConfig = createClientConfig(options, cliOptions).toConfig()
2727
let serverConfig = createServerConfig(options, cliOptions).toConfig()
2828

29-
// disable uglify for server
30-
serverConfig.optimization = { minimizer: [] }
31-
3229
// apply user config...
3330
const userConfig = options.siteConfig.configureWebpack
3431
if (userConfig) {
@@ -168,6 +165,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
168165
const styleChunk = stats.children[0].assets.find(a => {
169166
return /styles\.\w{8}\.js$/.test(a.name)
170167
})
168+
if (!styleChunk) return
171169
const styleChunkPath = path.resolve(outDir, styleChunk.name)
172170
const styleChunkContent = await fs.readFile(styleChunkPath, 'utf-8')
173171
await fs.remove(styleChunkPath)

lib/webpack/createBaseConfig.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = function createBaseConfig ({
1919
const config = new Config()
2020

2121
config
22-
.set('mode', isProd && !debug ? 'production' : 'development')
22+
.mode(isProd && !debug ? 'production' : 'development')
2323
.output
2424
.path(outDir)
2525
.filename(isProd ? 'assets/js/[name].[chunkhash:8].js' : 'assets/js/[name].js')
@@ -204,20 +204,17 @@ module.exports = function createBaseConfig ({
204204
// ensure all css are extracted together.
205205
// since most of the CSS will be from the theme and very little
206206
// CSS will be from async chunks
207-
config
208-
.set('optimization', {
209-
splitChunks: {
210-
cacheGroups: {
211-
styles: {
212-
name: 'styles',
213-
// necessary for extraction to include md files as well
214-
test: m => /css-extract/.test(m.type),
215-
chunks: 'all',
216-
enforce: true
217-
}
218-
}
207+
config.optimization.splitChunks({
208+
cacheGroups: {
209+
styles: {
210+
name: 'styles',
211+
// necessary to ensure async chunks are also extracted
212+
test: m => /css-extract/.test(m.type),
213+
chunks: 'all',
214+
enforce: true
219215
}
220-
})
216+
}
217+
})
221218
}
222219

223220
// inject constants

lib/webpack/createServerConfig.js

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ module.exports = function createServerConfig (options, cliOptions) {
1313
.target('node')
1414
.externals([/^vue|vue-router$/])
1515

16+
// no need to minimize server build
17+
config.optimization.minimize(false)
18+
1619
config
1720
.entry('app')
1821
.add(path.resolve(__dirname, '../app/serverEntry.js'))

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"file-loader": "^1.1.11",
5757
"fs-extra": "^5.0.0",
5858
"globby": "^8.0.1",
59-
"vuepress-html-webpack-plugin": "^3.2.0",
6059
"koa-connect": "^2.0.1",
6160
"koa-mount": "^3.0.0",
6261
"koa-static": "^4.0.2",
@@ -84,8 +83,9 @@
8483
"vue-router": "^3.0.1",
8584
"vue-server-renderer": "^2.5.16",
8685
"vue-template-compiler": "^2.5.16",
87-
"webpack": "^4.4.1",
88-
"webpack-chain": "^4.5.0",
86+
"vuepress-html-webpack-plugin": "^3.2.0",
87+
"webpack": "^4.5.0",
88+
"webpack-chain": "^4.6.0",
8989
"webpack-merge": "^4.1.2",
9090
"webpack-serve": "^0.3.1",
9191
"webpackbar": "^2.6.1",

0 commit comments

Comments
 (0)