Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,16 @@ module.exports = {

### css.extract

- Type: `boolean`
- Default: `true` (in production mode, always `false` otherwise)
- Type: `boolean | string`
- Default: `'production'`

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

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

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

Extracting CSS is always disabled in `development` since it breaks Hot Module Replacement.
Extracting CSS is disabled by default in `development` since it breaks Hot Module Replacement, can be enabled by setting this to `true`.

### css.sourceMap

Expand Down
13 changes: 13 additions & 0 deletions packages/@vue/cli-service/__tests__/css.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ test('css.extract', () => {
})
})

test('css.extract when development', () => {
const config = genConfig({
vue: {
css: {
extract: 'production'
}
}
}, 'development')
LANGS.forEach(lang => {
expect(findLoaders(config, lang)).not.toContain(extractLoaderPath)
})
})

test('css.sourceMap', () => {
const config = genConfig({
postcss: {},
Expand Down
4 changes: 2 additions & 2 deletions packages/@vue/cli-service/lib/config/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ module.exports = (api, options) => {

const {
modules = false,
extract = true,
extract = 'production',
sourceMap = false,
loaderOptions = {}
} = options.css || {}

const shadowMode = !!process.env.VUE_CLI_CSS_SHADOW_MODE
const isProd = process.env.NODE_ENV === 'production'
const shouldExtract = isProd && extract !== false && !shadowMode
const shouldExtract = ((!isProd && extract === true) || (isProd && (extract === true || extract === 'production'))) && !shadowMode
const filename = getAssetPath(
options,
`css/[name]${options.filenameHashing ? '.[contenthash:8]' : ''}.css`,
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const schema = createSchema(joi => joi.object({
// css
css: joi.object({
modules: joi.boolean(),
extract: joi.alternatives().try(joi.boolean(), joi.object()),
extract: joi.alternatives().try(joi.boolean(), joi.object(), joi.string().allow('production')),
sourceMap: joi.boolean(),
loaderOptions: joi.object({
css: joi.object(),
Expand Down