Skip to content

Commit 686ec25

Browse files
committed
feat: allow enfoce extract css in development
close #2002 BREAKING CHANGE: setting css.extract to true will now force extraction in development
1 parent d1a655c commit 686ec25

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

docs/config/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,16 @@ module.exports = {
198198

199199
### css.extract
200200

201-
- Type: `boolean`
202-
- Default: `true` (in production mode, always `false` otherwise)
201+
- Type: `boolean | Object`
202+
- Default: `true` in production, `false` in development
203203

204204
Whether to extract CSS in your components into a standalone CSS files (instead of inlined in JavaScript and injected dynamically).
205205

206-
This is also disabled by default when building as web components (styles are inlined and injected into shadowRoot).
206+
This is always disabled when building as web components (styles are inlined and injected into shadowRoot).
207207

208208
When building as a library, you can also set this to `false` to avoid your users having to import the CSS themselves.
209209

210-
Extracting CSS is always disabled in `development` since it breaks Hot Module Replacement.
210+
Extracting CSS is disabled by default in development mode since it is incompatible with CSS hot reloading. However, you can still enforce extraction in all cases by explicitly setting the value to `true`.
211211

212212
### css.sourceMap
213213

packages/@vue/cli-service/lib/config/css.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ const findExisting = (context, files) => {
1212
module.exports = (api, options) => {
1313
api.chainWebpack(webpackConfig => {
1414
const getAssetPath = require('../util/getAssetPath')
15+
const shadowMode = !!process.env.VUE_CLI_CSS_SHADOW_MODE
16+
const isProd = process.env.NODE_ENV === 'production'
1517

1618
const {
1719
modules = false,
18-
extract = true,
20+
extract = isProd,
1921
sourceMap = false,
2022
loaderOptions = {}
2123
} = options.css || {}
2224

23-
const shadowMode = !!process.env.VUE_CLI_CSS_SHADOW_MODE
24-
const isProd = process.env.NODE_ENV === 'production'
25-
const shouldExtract = isProd && extract !== false && !shadowMode
25+
const shouldExtract = extract !== false && !shadowMode
2626
const filename = getAssetPath(
2727
options,
2828
`css/[name]${options.filenameHashing ? '.[contenthash:8]' : ''}.css`,

0 commit comments

Comments
 (0)