@@ -48,6 +48,18 @@ export function importCSS(options: ImportCSSOptions): Plugin {
48
48
return
49
49
}
50
50
51
+ const hash = getSourceHash ( code )
52
+ const relativePath = path . relative ( rootDirectory , id )
53
+ const name = path . basename ( relativePath , '.module.css' )
54
+
55
+ const fileName = path . join (
56
+ path . dirname ( relativePath ) ,
57
+ path . format ( {
58
+ name : `${ name } -${ hash } ` ,
59
+ ext : '.css' ,
60
+ } ) ,
61
+ )
62
+
51
63
// When transforming CSS modules, we want to emit the generated CSS as an
52
64
// asset and include the generated file in our generated CSS Modules file
53
65
// which contains the classes. This makes sure that if the file containing
@@ -66,25 +78,24 @@ export function importCSS(options: ImportCSSOptions): Plugin {
66
78
cssModuleClasses = json
67
79
} ,
68
80
} ) ,
69
- ] ) . process ( code , { from : id } )
70
- const source = result . css
71
- const hash = getSourceHash ( source )
72
- const relativePath = path . relative ( rootDirectory , id )
73
- const name = path . basename ( relativePath , '.module.css' )
74
-
75
- const fileName = path . join (
76
- path . dirname ( relativePath ) ,
77
- path . format ( {
78
- name : `${ name } -${ hash } ` ,
79
- ext : '.css' ,
80
- } ) ,
81
- )
81
+ ] ) . process ( code , {
82
+ from : id ,
83
+ to : fileName ,
84
+ map : {
85
+ inline : false ,
86
+ } ,
87
+ } )
82
88
83
89
this . emitFile ( {
84
90
type : 'asset' ,
85
- source,
91
+ source : result . css ,
86
92
fileName,
87
93
} )
94
+ this . emitFile ( {
95
+ type : 'asset' ,
96
+ source : result . map . toString ( ) ,
97
+ fileName : `${ fileName } .map` ,
98
+ } )
88
99
89
100
const moduleInfo = this . getModuleInfo ( id )
90
101
const cssSource = `./${ path . basename ( fileName ) } `
0 commit comments