@@ -10,8 +10,8 @@ const Template = require("./Template");
1010class WebpackOptionsDefaulter extends OptionsDefaulter {
1111 constructor ( ) {
1212 super ( ) ;
13- this . set ( "devtool" , false ) ;
14- this . set ( "cache" , true ) ;
13+ this . set ( "devtool" , "make" , options => options . mode === "development" ? "eval" : false ) ;
14+ this . set ( "cache" , "make" , options => options . mode === "development" ) ;
1515
1616 this . set ( "context" , process . cwd ( ) ) ;
1717 this . set ( "target" , "web" ) ;
@@ -30,7 +30,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
3030 this . set ( "module.wrappedContextCritical" , false ) ;
3131 this . set ( "module.strictExportPresence" , false ) ;
3232 this . set ( "module.strictThisContextOnImports" , false ) ;
33- this . set ( "module.unsafeCache" , true ) ;
33+ this . set ( "module.unsafeCache" , "make" , options => ! ! options . cache ) ;
3434 this . set ( "module.rules" , [ ] ) ;
3535 this . set ( "module.defaultRules" , [ {
3636 type : "javascript/auto" ,
@@ -64,21 +64,29 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
6464 this . set ( "output.filename" , "[name].js" ) ;
6565 this . set ( "output.chunkFilename" , "make" , ( options ) => {
6666 const filename = options . output . filename ;
67- return filename . indexOf ( "[name]" ) >= 0 ? filename . replace ( "[name]" , "[id]" ) : "[id]." + filename ;
67+ const hasName = filename . indexOf ( "[name]" ) >= 0 ;
68+ const hasChunkHash = filename . indexOf ( "[chunkhash]" ) >= 0 ;
69+ // Anything with [chunkhash] is already fine
70+ if ( hasChunkHash ) return filename ;
71+ // Replace [name] with [id] because it doesn't require a name map
72+ if ( hasName ) return filename . replace ( "[name]" , "[id]" ) ;
73+ // Prefix "[id]." in front of the basename
74+ return filename . replace ( / ( ^ | \/ ) ( [ ^ / ] * (?: \? | $ ) ) / , "$1[id].$2" ) ;
6875 } ) ;
6976 this . set ( "output.webassemblyModuleFilename" , "[modulehash].module.wasm" ) ;
7077 this . set ( "output.library" , "" ) ;
7178 this . set ( "output.hotUpdateFunction" , "make" , ( options ) => {
7279 return Template . toIdentifier ( "webpackHotUpdate" + options . output . library ) ;
7380 } ) ;
7481 this . set ( "output.jsonpFunction" , "make" , ( options ) => {
75- return Template . toIdentifier ( "webpackJsonp" + options . output . library ) ;
82+ return Template . toIdentifier ( "webpackJsonp" + Template . toIdentifier ( options . output . library ) ) ;
7683 } ) ;
7784 this . set ( "output.devtoolNamespace" , "make" , ( options ) => {
7885 return options . output . library || "" ;
7986 } ) ;
8087 this . set ( "output.libraryTarget" , "var" ) ;
8188 this . set ( "output.path" , process . cwd ( ) ) ;
89+ this . set ( "output.pathinfo" , "make" , options => options . mode === "development" ) ;
8290 this . set ( "output.sourceMapFilename" , "[file].map[query]" ) ;
8391 this . set ( "output.hotUpdateChunkFilename" , "[id].[hash].hot-update.js" ) ;
8492 this . set ( "output.hotUpdateMainFilename" , "[hash].hot-update.json" ) ;
@@ -114,7 +122,21 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
114122 } ) ;
115123 this . set ( "performance.maxAssetSize" , 250000 ) ;
116124 this . set ( "performance.maxEntrypointSize" , 250000 ) ;
117- this . set ( "performance.hints" , false ) ;
125+ this . set ( "performance.hints" , "make" , options => options . mode === "production" ? "warning" : false ) ;
126+
127+ this . set ( "optimization.removeAvailableModules" , true ) ;
128+ this . set ( "optimization.removeEmptyChunks" , true ) ;
129+ this . set ( "optimization.mergedDuplicateChunks" , true ) ;
130+ this . set ( "optimization.flagIncludedChunks" , "make" , options => options . mode === "production" ) ;
131+ this . set ( "optimization.occurrenceOrder" , "make" , options => options . mode === "production" ) ;
132+ this . set ( "optimization.sideEffects" , "make" , options => options . mode === "production" ) ;
133+ this . set ( "optimization.providedExports" , true ) ;
134+ this . set ( "optimization.usedExports" , "make" , options => options . mode === "production" ) ;
135+ this . set ( "optimization.concatenateModules" , "make" , options => options . mode === "production" ) ;
136+ this . set ( "optimization.noEmitOnErrors" , "make" , options => options . mode === "production" ) ;
137+ this . set ( "optimization.namedModules" , "make" , options => options . mode === "development" ) ;
138+ this . set ( "optimization.namedChunks" , "make" , options => options . mode === "development" ) ;
139+ this . set ( "optimization.nodeEnv" , "make" , options => options . mode ) ;
118140
119141 this . set ( "resolve" , "call" , value => Object . assign ( { } , value ) ) ;
120142 this . set ( "resolve.unsafeCache" , true ) ;
0 commit comments