Skip to content

Commit accc484

Browse files
committed
fix(bundler-webpack): always extract css file in build mode
1 parent f8cd4a3 commit accc484

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

packages/@vuepress/bundler-webpack/src/build/createClientConfig.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,41 +45,41 @@ export const createClientConfig = (
4545
}
4646

4747
// optimizations for production mode
48-
if (app.env.isProd) {
49-
// extract-css
50-
config.plugin('extract-css').use(require('mini-css-extract-plugin'), [
51-
{
52-
filename: 'assets/css/styles.[chunkhash:8].css',
53-
},
54-
])
48+
// extract-css
49+
config.plugin('extract-css').use(require('mini-css-extract-plugin'), [
50+
{
51+
filename: app.env.isProd
52+
? 'assets/css/styles.[chunkhash:8].css'
53+
: 'assets/css/styles.css',
54+
},
55+
])
5556

56-
config.optimization.splitChunks({
57-
cacheGroups: {
58-
// ensure all css are extracted together.
59-
// since most of the CSS will be from the theme and very little
60-
// CSS will be from async chunks
61-
styles: {
62-
idHint: 'styles',
63-
// necessary to ensure async chunks are also extracted
64-
test: (m) => /css\/mini-extract/.test(m.type),
65-
chunks: 'all',
66-
enforce: true,
67-
reuseExistingChunk: true,
68-
},
69-
// extract external library to a standalone chunk
70-
vendor: {
71-
idHint: 'vendor',
72-
test: /node_modules/,
73-
chunks: 'all',
74-
priority: -10,
75-
reuseExistingChunk: true,
76-
},
57+
config.optimization.splitChunks({
58+
cacheGroups: {
59+
// ensure all css are extracted together.
60+
// since most of the CSS will be from the theme and very little
61+
// CSS will be from async chunks
62+
styles: {
63+
idHint: 'styles',
64+
// necessary to ensure async chunks are also extracted
65+
test: (m) => /css\/mini-extract/.test(m.type),
66+
chunks: 'all',
67+
enforce: true,
68+
reuseExistingChunk: true,
7769
},
78-
})
70+
// extract external library to a standalone chunk
71+
vendor: {
72+
idHint: 'vendor',
73+
test: /node_modules/,
74+
chunks: 'all',
75+
priority: -10,
76+
reuseExistingChunk: true,
77+
},
78+
},
79+
})
7980

80-
// enable runtimeChunk
81-
config.optimization.runtimeChunk(true)
82-
}
81+
// enable runtimeChunk
82+
config.optimization.runtimeChunk(true)
8383

8484
// disable performance hints
8585
if (!app.env.isDebug) {

packages/@vuepress/bundler-webpack/src/config/handleModuleStyles.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type * as Config from 'webpack-chain'
22
import type { App } from '@vuepress/core'
3-
import * as MiniCSSExtractPlugin from 'mini-css-extract-plugin'
43
import type {
54
WebpackBundlerOptions,
65
LoaderOptions,
@@ -59,7 +58,9 @@ export const handleModuleStyles = ({
5958
}): void => {
6059
if (!isServer) {
6160
if (isBuild) {
62-
rule.use('extract-css-loader').loader(MiniCSSExtractPlugin.loader)
61+
rule
62+
.use('extract-css-loader')
63+
.loader(require('mini-css-extract-plugin').loader)
6364
} else {
6465
rule.use('style-loader').loader('style-loader')
6566
}

0 commit comments

Comments
 (0)