Skip to content

Commit

Permalink
refactor: simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Oct 23, 2021
1 parent 2fe638a commit 7ef446d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/vite/src/node/plugins/css.ts
Expand Up @@ -55,8 +55,8 @@ export interface CSSOptions {
postcss?:
| string
| (Postcss.ProcessOptions & {
plugins?: Postcss.Plugin[]
})
plugins?: Postcss.Plugin[]
})
}

export interface CSSModulesOptions {
Expand Down Expand Up @@ -308,20 +308,18 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {

// build CSS handling ----------------------------------------------------

const used = usedRE.test(id)

// record css
if (!inlined) {
styles.set(id, css)
} else if (!modulesCode && used) {
css = await minifyCSS(css, config)
}

return {
code:
modulesCode ||
(used
? `export default ${JSON.stringify(css)}`
(usedRE.test(id)
? `export default ${JSON.stringify(
inlined ? await minifyCSS(css, config) : css
)}`
: `export default ''`),
map: { mappings: '' },
// avoid the css module from being tree-shaken so that we can retrieve
Expand Down

0 comments on commit 7ef446d

Please sign in to comment.