@@ -15,6 +15,7 @@ import { CompileResult } from './interfaces';
15
15
import RollupResult from './RollupResult' ;
16
16
17
17
const stderr = console . error . bind ( console ) ;
18
+ const INJECT_STYLES_ID = 'inject_styles' ;
18
19
19
20
let rollup : any ;
20
21
@@ -123,6 +124,20 @@ export default class RollupCompiler {
123
124
}
124
125
mod . plugins . push ( {
125
126
name : 'sapper-internal' ,
127
+ buildStart ( this : PluginContext ) : void {
128
+ this . emitFile ( {
129
+ type : 'chunk' ,
130
+ id : INJECT_STYLES_ID ,
131
+ name : INJECT_STYLES_ID ,
132
+ preserveSignature : 'strict'
133
+ } ) ;
134
+ } ,
135
+ load ( id : string ) {
136
+ return id === INJECT_STYLES_ID ? { code : inject_styles , moduleSideEffects : 'no-treeshake' } : null ;
137
+ } ,
138
+ resolveId ( importee : string , importer : string ) {
139
+ return importee === INJECT_STYLES_ID ? INJECT_STYLES_ID : null ;
140
+ } ,
126
141
renderChunk ( code : string , chunk : RenderedChunk ) {
127
142
that . chunks . push ( chunk ) ;
128
143
} ,
@@ -166,6 +181,8 @@ export default class RollupCompiler {
166
181
return Array . from ( css_files ) ;
167
182
} ;
168
183
184
+ const inject_styles_file = Object . keys ( bundle ) . find ( f => f . startsWith ( 'inject_styles' ) ) ;
185
+
169
186
let has_css = false ;
170
187
for ( const name in bundle ) {
171
188
const chunk = < OutputChunk > bundle [ name ] ;
@@ -190,17 +207,13 @@ export default class RollupCompiler {
190
207
191
208
if ( chunk_has_css ) {
192
209
has_css = true ;
193
- chunk . code += `\nimport __inject_styles from './inject_styles.js ';` ;
210
+ chunk . code += `\nimport __inject_styles from './${ inject_styles_file } ';` ;
194
211
}
195
212
}
196
213
}
197
214
198
- if ( has_css ) {
199
- this . emitFile ( {
200
- type : 'asset' ,
201
- fileName : 'inject_styles.js' ,
202
- source : inject_styles
203
- } ) ;
215
+ if ( ! has_css ) {
216
+ delete bundle [ inject_styles_file ] ;
204
217
}
205
218
206
219
// Store the build dependencies so that we can create build.json
0 commit comments