@@ -56,7 +56,7 @@ const {
5656
5757/**
5858 * @typedef {object } NormalizedPluginOptions
59- * @property {Filename } filename filename
59+ * @property {Filename= } filename filename
6060 * @property {ChunkFilename= } chunkFilename chunk filename
6161 * @property {boolean } ignoreOrder true when need to ignore order, otherwise false
6262 * @property {string | ((linkTag: HTMLLinkElement) => void)= } insert a link insert place or a custom insert function
@@ -568,7 +568,6 @@ class MiniCssExtractPlugin {
568568 * @type {NormalizedPluginOptions }
569569 */
570570 this . options = {
571- filename : DEFAULT_FILENAME ,
572571 ignoreOrder : false ,
573572 // TODO remove in the next major release
574573 experimentalUseImportModule : undefined ,
@@ -591,39 +590,49 @@ class MiniCssExtractPlugin {
591590 : options . linkType ,
592591 attributes : options . attributes ,
593592 } ;
593+ }
594594
595- if ( ! this . options . chunkFilename ) {
596- const { filename } = this . options ;
597-
598- if ( typeof filename !== "function" ) {
599- const hasName = /** @type {string } */ ( filename ) . includes ( "[name]" ) ;
600- const hasId = /** @type {string } */ ( filename ) . includes ( "[id]" ) ;
595+ /**
596+ * @param {Compiler } compiler compiler
597+ */
598+ apply ( compiler ) {
599+ // Finally normalize filenames based on compiler options
600+ const normalizedFilename =
601+ this . options . filename ||
602+ compiler . options . output . cssFilename ||
603+ DEFAULT_FILENAME ;
604+ let normalizedChunkFilename =
605+ this . options . chunkFilename || compiler . options . output . cssChunkFilename ;
606+
607+ if ( ! normalizedChunkFilename ) {
608+ if ( typeof normalizedFilename !== "function" ) {
609+ const hasName = /** @type {string } */ ( normalizedFilename ) . includes (
610+ "[name]" ,
611+ ) ;
612+ const hasId = /** @type {string } */ ( normalizedFilename ) . includes (
613+ "[id]" ,
614+ ) ;
601615 const hasChunkHash =
602616 /** @type {string } */
603- ( filename ) . includes ( "[chunkhash]" ) ;
617+ ( normalizedFilename ) . includes ( "[chunkhash]" ) ;
604618 const hasContentHash =
605619 /** @type {string } */
606- ( filename ) . includes ( "[contenthash]" ) ;
620+ ( normalizedFilename ) . includes ( "[contenthash]" ) ;
607621
608622 // Anything changing depending on chunk is fine
609623 if ( hasChunkHash || hasContentHash || hasName || hasId ) {
610- this . options . chunkFilename = filename ;
624+ normalizedChunkFilename = normalizedFilename ;
611625 } else {
612626 // Otherwise prefix "[id]." in front of the basename to make it changing
613- this . options . chunkFilename =
627+ normalizedChunkFilename =
614628 /** @type {string } */
615- ( filename ) . replace ( / ( ^ | \/ ) ( [ ^ / ] * (?: \? | $ ) ) / , "$1[id].$2" ) ;
629+ ( normalizedFilename ) . replace ( / ( ^ | \/ ) ( [ ^ / ] * (?: \? | $ ) ) / , "$1[id].$2" ) ;
616630 }
617631 } else {
618- this . options . chunkFilename = "[id].css" ;
632+ normalizedChunkFilename = "[id].css" ;
619633 }
620634 }
621- }
622635
623- /**
624- * @param {Compiler } compiler compiler
625- */
626- apply ( compiler ) {
627636 const { webpack } = compiler ;
628637
629638 if (
@@ -743,8 +752,8 @@ class MiniCssExtractPlugin {
743752 /** @type {string } */
744753 (
745754 chunk . canBeInitial ( )
746- ? this . options . filename
747- : this . options . chunkFilename
755+ ? normalizedFilename
756+ : normalizedChunkFilename
748757 ) ;
749758
750759 if ( renderedModules . length > 0 ) {
@@ -1215,8 +1224,8 @@ class MiniCssExtractPlugin {
12151224 enabledChunks . add ( chunk ) ;
12161225
12171226 if (
1218- typeof this . options . chunkFilename === "string" &&
1219- / \[ ( f u l l ) ? h a s h ( : \d + ) ? \] / . test ( this . options . chunkFilename )
1227+ typeof normalizedChunkFilename === "string" &&
1228+ / \[ ( f u l l ) ? h a s h ( : \d + ) ? \] / . test ( normalizedChunkFilename )
12201229 ) {
12211230 set . add ( RuntimeGlobals . getFullHash ) ;
12221231 }
@@ -1239,8 +1248,8 @@ class MiniCssExtractPlugin {
12391248 }
12401249
12411250 return referencedChunk . canBeInitial ( )
1242- ? /** @type {Filename } */ ( this . options . filename )
1243- : /** @type {ChunkFilename } */ ( this . options . chunkFilename ) ;
1251+ ? /** @type {Filename } */ ( normalizedFilename )
1252+ : /** @type {ChunkFilename } */ ( normalizedChunkFilename ) ;
12441253 } ,
12451254 set . has ( RuntimeGlobals . hmrDownloadUpdateHandlers ) ,
12461255 ) ,
0 commit comments