@@ -86,6 +86,7 @@ export const cssLangRE = new RegExp(cssLangs)
86
86
const cssModuleRE = new RegExp ( `\\.module${ cssLangs } ` )
87
87
const directRequestRE = / ( \? | & ) d i r e c t \b /
88
88
const commonjsProxyRE = / \? c o m m o n j s - p r o x y /
89
+ const inlineRE = / ( \? | & ) i n l i n e \b /
89
90
90
91
const enum PreprocessLang {
91
92
less = 'less' ,
@@ -190,36 +191,37 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
190
191
if ( server ) {
191
192
// server only logic for handling CSS @import dependency hmr
192
193
const { moduleGraph } = server
193
- const thisModule = moduleGraph . getModuleById ( id ) !
194
-
195
- // CSS modules cannot self-accept since it exports values
196
- const isSelfAccepting = ! modules
197
- if ( deps ) {
198
- // record deps in the module graph so edits to @import css can trigger
199
- // main import to hot update
200
- const depModules = new Set < string | ModuleNode > ( )
201
- for ( const file of deps ) {
202
- depModules . add (
203
- cssLangRE . test ( file )
204
- ? moduleGraph . createFileOnlyEntry ( file )
205
- : await moduleGraph . ensureEntryFromUrl (
206
- await fileToUrl ( file , config , this )
207
- )
194
+ const thisModule = moduleGraph . getModuleById ( id )
195
+ if ( thisModule ) {
196
+ // CSS modules cannot self-accept since it exports values
197
+ const isSelfAccepting = ! modules
198
+ if ( deps ) {
199
+ // record deps in the module graph so edits to @import css can trigger
200
+ // main import to hot update
201
+ const depModules = new Set < string | ModuleNode > ( )
202
+ for ( const file of deps ) {
203
+ depModules . add (
204
+ cssLangRE . test ( file )
205
+ ? moduleGraph . createFileOnlyEntry ( file )
206
+ : await moduleGraph . ensureEntryFromUrl (
207
+ await fileToUrl ( file , config , this )
208
+ )
209
+ )
210
+ }
211
+ moduleGraph . updateModuleInfo (
212
+ thisModule ,
213
+ depModules ,
214
+ // The root CSS proxy module is self-accepting and should not
215
+ // have an explicit accept list
216
+ new Set ( ) ,
217
+ isSelfAccepting
208
218
)
219
+ for ( const file of deps ) {
220
+ this . addWatchFile ( file )
221
+ }
222
+ } else {
223
+ thisModule . isSelfAccepting = isSelfAccepting
209
224
}
210
- moduleGraph . updateModuleInfo (
211
- thisModule ,
212
- depModules ,
213
- // The root CSS proxy module is self-accepting and should not
214
- // have an explicit accept list
215
- new Set ( ) ,
216
- isSelfAccepting
217
- )
218
- for ( const file of deps ) {
219
- this . addWatchFile ( file )
220
- }
221
- } else {
222
- thisModule . isSelfAccepting = isSelfAccepting
223
225
}
224
226
}
225
227
@@ -255,11 +257,12 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
255
257
hasEmitted = false
256
258
} ,
257
259
258
- transform ( css , id , ssr ) {
260
+ async transform ( css , id , ssr ) {
259
261
if ( ! cssLangRE . test ( id ) || commonjsProxyRE . test ( id ) ) {
260
262
return
261
263
}
262
264
265
+ const inlined = inlineRE . test ( id )
263
266
const modules = cssModulesCache . get ( config ) ! . get ( id )
264
267
const modulesCode =
265
268
modules && dataToEsm ( modules , { namedExports : true , preferConst : true } )
@@ -272,6 +275,9 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
272
275
if ( ssr ) {
273
276
return modulesCode || `export default ${ JSON . stringify ( css ) } `
274
277
}
278
+ if ( inlined ) {
279
+ return `export default ${ JSON . stringify ( css ) } `
280
+ }
275
281
return [
276
282
`import { updateStyle, removeStyle } from ${ JSON . stringify (
277
283
path . posix . join ( config . base , CLIENT_PUBLIC_PATH )
@@ -289,7 +295,11 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
289
295
// build CSS handling ----------------------------------------------------
290
296
291
297
// record css
292
- styles . set ( id , css )
298
+ if ( ! inlined ) {
299
+ styles . set ( id , css )
300
+ } else {
301
+ css = await minifyCSS ( css , config )
302
+ }
293
303
294
304
return {
295
305
code : modulesCode || `export default ${ JSON . stringify ( css ) } ` ,
0 commit comments