1
1
import * as path from "path"
2
- import { RuleSetRule , WebpackPluginInstance } from "webpack"
2
+ import { RuleSetRule , WebpackPluginInstance , Configuration } from "webpack"
3
3
import { GraphQLSchema } from "graphql"
4
4
import { Plugin as PostCSSPlugin } from "postcss"
5
5
import autoprefixer from "autoprefixer"
@@ -65,12 +65,16 @@ type CSSModulesOptions =
65
65
exportOnlyLocals ?: boolean
66
66
}
67
67
68
- type MiniCSSExtractLoaderModuleOptions =
69
- | undefined
70
- | boolean
71
- | {
72
- namedExport ?: boolean
73
- }
68
+ interface IMiniCSSExtractLoaderModuleOptions {
69
+ filename ?: Required < Configuration > [ "output" ] [ "filename" ] | undefined
70
+ chunkFilename ?: Required < Configuration > [ "output" ] [ "chunkFilename" ] | undefined
71
+ experimentalUseImportModule ?: boolean | undefined
72
+ ignoreOrder ?: boolean | undefined
73
+ insert ?: string | ( ( linkTag : any ) => void ) | undefined
74
+ attributes ?: Record < string , string > | undefined
75
+ linkType ?: string | false | "text/css" | undefined
76
+ runtime ?: boolean | undefined
77
+ }
74
78
/**
75
79
* Utils that produce webpack `loader` objects
76
80
*/
@@ -234,27 +238,13 @@ export const createWebpackUtils = (
234
238
}
235
239
} ,
236
240
237
- miniCssExtract : (
238
- options : {
239
- modules ?: MiniCSSExtractLoaderModuleOptions
240
- } = { }
241
- ) => {
242
- let moduleOptions : MiniCSSExtractLoaderModuleOptions = undefined
243
-
241
+ miniCssExtract : ( options : IMiniCSSExtractLoaderModuleOptions = { } ) => {
242
+ // @ts -ignore - legacy modules
244
243
const { modules, ...restOptions } = options
245
244
246
- if ( typeof modules === `boolean` && options . modules ) {
247
- moduleOptions = {
248
- namedExport : true ,
249
- }
250
- } else {
251
- moduleOptions = modules
252
- }
253
-
254
245
return {
255
246
loader : MiniCssExtractPlugin . loader ,
256
247
options : {
257
- modules : moduleOptions ,
258
248
...restOptions ,
259
249
} ,
260
250
}
@@ -283,13 +273,15 @@ export const createWebpackUtils = (
283
273
loader : require . resolve ( `css-loader` ) ,
284
274
options : {
285
275
// Absolute urls (https or //) are not send to this function. Only resolvable paths absolute or relative ones.
286
- url : function ( url : string ) : boolean {
287
- // When an url starts with /
288
- if ( url . startsWith ( `/` ) ) {
289
- return false
290
- }
291
-
292
- return true
276
+ url : {
277
+ filter : function ( url : string ) : boolean {
278
+ // When an url starts with /
279
+ if ( url . startsWith ( `/` ) ) {
280
+ return false
281
+ }
282
+
283
+ return true
284
+ } ,
293
285
} ,
294
286
sourceMap : ! PRODUCTION ,
295
287
modules : modulesOptions ,
@@ -350,6 +342,7 @@ export const createWebpackUtils = (
350
342
}
351
343
} ,
352
344
345
+ // TODO(v5): Consider removing this (as not used anymore internally)
353
346
url : ( options = { } ) => {
354
347
return {
355
348
loader : require . resolve ( `url-loader` ) ,
@@ -545,8 +538,11 @@ export const createWebpackUtils = (
545
538
*/
546
539
rules . fonts = ( ) : RuleSetRule => {
547
540
return {
548
- use : [ loaders . url ( ) ] ,
549
541
test : / \. ( e o t | o t f | t t f | w o f f ( 2 ) ? ) ( \? .* ) ? $ / ,
542
+ type : `asset/resource` ,
543
+ generator : {
544
+ filename : `${ assetRelativeRoot } [name]-[hash][ext]` ,
545
+ } ,
550
546
}
551
547
}
552
548
@@ -556,8 +552,11 @@ export const createWebpackUtils = (
556
552
*/
557
553
rules . images = ( ) : RuleSetRule => {
558
554
return {
559
- use : [ loaders . url ( ) ] ,
560
555
test : / \. ( i c o | s v g | j p g | j p e g | p n g | g i f | w e b p | a v i f ) ( \? .* ) ? $ / ,
556
+ type : `asset/resource` ,
557
+ generator : {
558
+ filename : `${ assetRelativeRoot } [name]-[hash][ext]` ,
559
+ } ,
561
560
}
562
561
}
563
562
@@ -567,8 +566,11 @@ export const createWebpackUtils = (
567
566
*/
568
567
rules . media = ( ) : RuleSetRule => {
569
568
return {
570
- use : [ loaders . url ( ) ] ,
571
569
test : / \. ( m p 4 | w e b m | o g v | w a v | m p 3 | m 4 a | a a c | o g a | f l a c ) $ / ,
570
+ type : `asset/resource` ,
571
+ generator : {
572
+ filename : `${ assetRelativeRoot } [name]-[hash][ext]` ,
573
+ } ,
572
574
}
573
575
}
574
576
0 commit comments