@@ -24,7 +24,7 @@ class CssDependency extends webpack.Dependency {
24
24
{ identifier, content, media, sourceMap } ,
25
25
context ,
26
26
identifierIndex ,
27
- theme ,
27
+ theme
28
28
) {
29
29
super ( ) ;
30
30
@@ -150,7 +150,7 @@ class MiniCssExtractPlugin {
150
150
) ;
151
151
}
152
152
}
153
- this . themes = [ 'default' ] . concat ( this . options . themes ) ;
153
+ this . themes = [ 'default' ] . concat ( this . options . themes || [ ] ) ;
154
154
}
155
155
156
156
apply ( compiler ) {
@@ -159,7 +159,7 @@ class MiniCssExtractPlugin {
159
159
const loaderContext = lc ;
160
160
const module = m ;
161
161
162
- loaderContext . themes = this . themes ;
162
+ loaderContext . themes = this . themes ;
163
163
loaderContext [ MODULE_TYPE ] = ( content , theme ) => {
164
164
if ( ! Array . isArray ( content ) && content != null ) {
165
165
throw new Error (
@@ -174,7 +174,9 @@ class MiniCssExtractPlugin {
174
174
for ( const line of content ) {
175
175
const count = identifierCountMap . get ( line . identifier ) || 0 ;
176
176
177
- module . addDependency ( new CssDependency ( line , m . context , count , theme ) ) ;
177
+ module . addDependency (
178
+ new CssDependency ( line , m . context , count , theme )
179
+ ) ;
178
180
identifierCountMap . set ( line . identifier , count + 1 ) ;
179
181
}
180
182
} ;
@@ -193,62 +195,73 @@ class MiniCssExtractPlugin {
193
195
compilation . mainTemplate . hooks . renderManifest . tap (
194
196
pluginName ,
195
197
( result , { chunk } ) => {
196
- for ( const theme of this . themes ) {
197
- const renderedModules = Array . from ( chunk . modulesIterable ) . filter (
198
- ( module ) => module . type === MODULE_TYPE && module . theme === theme
199
- ) ;
198
+ for ( const theme of this . themes ) {
199
+ const renderedModules = Array . from ( chunk . modulesIterable ) . filter (
200
+ ( module ) => module . type === MODULE_TYPE && module . theme === theme
201
+ ) ;
200
202
201
- if ( renderedModules . length > 0 ) {
202
- result . push ( {
203
- render : ( ) =>
204
- this . renderContentAsset (
205
- compilation ,
203
+ if ( renderedModules . length > 0 ) {
204
+ result . push ( {
205
+ render : ( ) =>
206
+ this . renderContentAsset (
207
+ compilation ,
208
+ chunk ,
209
+ renderedModules ,
210
+ compilation . runtimeTemplate . requestShortener
211
+ ) ,
212
+ filenameTemplate : ( { chunk : chunkData } ) => {
213
+ return theme === 'default'
214
+ ? this . options . moduleFilename ( chunkData )
215
+ : this . options . themeModuleFilename ( theme ) ;
216
+ } ,
217
+ pathOptions : {
206
218
chunk,
207
- renderedModules ,
208
- compilation . runtimeTemplate . requestShortener
209
- ) ,
210
- filenameTemplate : ( { chunk : chunkData } ) => {
211
- return theme === 'default' ? this . options . moduleFilename ( chunkData ) : this . options . themeModuleFilename ( theme )
212
- } ,
213
- pathOptions : {
214
- chunk,
215
- contentHashType : MODULE_TYPE ,
216
- } ,
217
- identifier : theme !== 'default' ? `${ pluginName } .theme.${ chunk . id } ` :`${ pluginName } .${ chunk . id } ` ,
218
- hash : chunk . contentHash [ MODULE_TYPE ] ,
219
- } ) ;
219
+ contentHashType : MODULE_TYPE ,
220
+ } ,
221
+ identifier :
222
+ theme !== 'default'
223
+ ? `${ pluginName } .theme.${ chunk . id } `
224
+ : `${ pluginName } .${ chunk . id } ` ,
225
+ hash : chunk . contentHash [ MODULE_TYPE ] ,
226
+ } ) ;
227
+ }
220
228
}
221
229
}
222
- }
223
230
) ;
224
231
225
232
compilation . chunkTemplate . hooks . renderManifest . tap (
226
233
pluginName ,
227
234
( result , { chunk } ) => {
228
- for ( const theme of this . themes ) {
229
- const renderedModules = Array . from ( chunk . modulesIterable ) . filter (
230
- ( module ) => module . type === MODULE_TYPE && module . theme === theme
231
- ) ;
232
- if ( renderedModules . length > 0 ) {
233
- result . push ( {
234
- render : ( ) =>
235
- this . renderContentAsset (
236
- compilation ,
235
+ for ( const theme of this . themes ) {
236
+ const renderedModules = Array . from ( chunk . modulesIterable ) . filter (
237
+ ( module ) => module . type === MODULE_TYPE && module . theme === theme
238
+ ) ;
239
+ if ( renderedModules . length > 0 ) {
240
+ result . push ( {
241
+ render : ( ) =>
242
+ this . renderContentAsset (
243
+ compilation ,
244
+ chunk ,
245
+ renderedModules ,
246
+ compilation . runtimeTemplate . requestShortener
247
+ ) ,
248
+ filenameTemplate :
249
+ theme === 'default'
250
+ ? this . options . chunkFilename
251
+ : `theme-${ theme } -${ this . options . chunkFilename } ` ,
252
+ pathOptions : {
237
253
chunk,
238
- renderedModules ,
239
- compilation . runtimeTemplate . requestShortener
240
- ) ,
241
- filenameTemplate : theme === 'default' ? this . options . chunkFilename : `theme-${ theme } -${ this . options . chunkFilename } ` ,
242
- pathOptions : {
243
- chunk,
244
- contentHashType : MODULE_TYPE ,
245
- } ,
246
- identifier : theme !== 'default' ? `${ pluginName } .${ theme } .${ chunk . id } ` : `${ pluginName } .${ chunk . id } ` ,
247
- hash : chunk . contentHash [ MODULE_TYPE ] ,
248
- } ) ;
254
+ contentHashType : MODULE_TYPE ,
255
+ } ,
256
+ identifier :
257
+ theme !== 'default'
258
+ ? `${ pluginName } .${ theme } .${ chunk . id } `
259
+ : `${ pluginName } .${ chunk . id } ` ,
260
+ hash : chunk . contentHash [ MODULE_TYPE ] ,
261
+ } ) ;
262
+ }
249
263
}
250
264
}
251
- }
252
265
) ;
253
266
254
267
compilation . mainTemplate . hooks . hashForChunk . tap (
0 commit comments