Skip to content

Commit e46ac20

Browse files
haoqunjiangNataliaTepluhina
authored andcommitted
docs: add warnings on css sideEffects (#4836)
These warnings are originally stated in the vue-loader documentation, but the CLI documentation perhaps have more visibility. Fixes #4832
1 parent f929158 commit e46ac20

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

docs/guide/build-targets.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ A lib build outputs:
5050

5151
- `dist/myLib.css`: Extracted CSS file (can be forced into inlined by setting `css: { extract: false }` in `vue.config.js`)
5252

53+
::: warning
54+
If you are developing a library or in a monorepo, please be aware that CSS imports **are side effects**. Make sure to **remove** `"sideEffects": false` in the `package.json`, otherwise CSS chunks will be dropped by webpack in production builds.
55+
:::
56+
5357
### Vue vs. JS/TS Entry Files
5458

5559
When using a `.vue` file as entry, your library will directly expose the Vue component itself, because the component is always the default export.
@@ -148,7 +152,7 @@ Now on the page, the user only needs to include Vue and the entry file:
148152

149153
When building a [Webcomponent](#web-component) or [Library](#library), the entry point is not `main.js`, but an `entry-wc.js` file, generated here: [https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/commands/build/resolveWcEntry.js](https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/commands/build/resolveWcEntry.js)
150154

151-
So to use vuex in web component target, you need to initialize the store in `App.vue`:
155+
So to use vuex in web component target, you need to initialize the store in `App.vue`:
152156

153157
``` js
154158
import store from './store'

docs/zh/guide/build-targets.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ dist/myLib.css 0.33 kb 0.23 kb
5454

5555
- `dist/myLib.css`:提取出来的 CSS 文件 (可以通过在 `vue.config.js` 中设置 `css: { extract: false }` 强制内联)
5656

57+
::: warning 警告
58+
如果你在开发一个库或多项目仓库 (monorepo),请注意导入 CSS **是具有副作用的**。请确保在 `package.json`**移除** `"sideEffects": false`,否则 CSS 代码块会在生产环境构建时被 webpack 丢掉。
59+
:::
60+
5761
### Vue vs. JS/TS 入口文件
5862

5963
当使用一个 `.vue` 文件作为入口时,你的库会直接暴露这个 Vue 组件本身,因为组件始终是默认导出的内容。

0 commit comments

Comments
 (0)