Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): css not be treeshake #1216

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 3 additions & 11 deletions src/node/build/buildPluginCss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import slash from 'slash'
const debug = require('debug')('vite:build:css')

const cssInjectionMarker = `__VITE_CSS__`
const cssInjectionRE = /__VITE_CSS__\(\);?/g

interface BuildCssOption {
root: string
Expand Down Expand Up @@ -128,16 +127,10 @@ export const createBuildCssPlugin = ({
return {
code: modules
? dataToEsm(modules, { namedExports: true })
: (cssCodeSplit
? // If code-splitting CSS, inject a fake marker to avoid the module
// from being tree-shaken. This preserves the .css file as a
// module in the chunk's metadata so that we can retrieve them in
// renderChunk.
`${cssInjectionMarker}()\n`
: ``) + `export default ${JSON.stringify(css)}`,
: `export default ${JSON.stringify(css)}`,
underfin marked this conversation as resolved.
Show resolved Hide resolved
map: null,
// #795 css always has side effect
moduleSideEffects: true
// css always not be treeshake
moduleSideEffects: 'no-treeshake'
}
}
},
Expand All @@ -161,7 +154,6 @@ export const createBuildCssPlugin = ({
}

if (cssCodeSplit) {
code = code.replace(cssInjectionRE, '')
if (!code.trim()) {
// this is a shared CSS-only chunk that is empty.
emptyChunks.add(chunk.fileName)
Expand Down