@@ -35,6 +35,8 @@ const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
35
35
// makes for a smoother build process.
36
36
const shouldInlineRuntimeChunk = process . env . INLINE_RUNTIME_CHUNK !== 'false' ;
37
37
38
+ const isExtendingEslintConfig = process . env . EXTEND_ESLINT === 'true' ;
39
+
38
40
const imageInlineSizeLimit = parseInt (
39
41
process . env . IMAGE_INLINE_SIZE_LIMIT || '10000'
40
42
) ;
@@ -59,32 +61,23 @@ module.exports = function(webpackEnv) {
59
61
const isEnvProductionProfile =
60
62
isEnvProduction && process . argv . includes ( '--profile' ) ;
61
63
62
- // Webpack uses `publicPath` to determine where the app is being served from.
63
- // It requires a trailing slash, or the file assets will get an incorrect path.
64
- // In development, we always serve from the root. This makes config easier.
65
- const publicPath = isEnvProduction
66
- ? paths . servedPath
67
- : isEnvDevelopment && '/' ;
68
- // Some apps do not use client-side routing with pushState.
69
- // For these, "homepage" can be set to "." to enable relative asset paths.
70
- const shouldUseRelativeAssetPaths = publicPath === './' ;
71
-
72
- // `publicUrl` is just like `publicPath`, but we will provide it to our app
64
+ // We will provide `paths.publicUrlOrPath` to our app
73
65
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
74
66
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
75
- const publicUrl = isEnvProduction
76
- ? publicPath . slice ( 0 , - 1 )
77
- : isEnvDevelopment && '' ;
78
67
// Get environment variables to inject into our app.
79
- const env = getClientEnvironment ( publicUrl ) ;
68
+ const env = getClientEnvironment ( paths . publicUrlOrPath . slice ( 0 , - 1 ) ) ;
80
69
81
70
// common function to get style loaders
82
71
const getStyleLoaders = ( cssOptions , preProcessor ) => {
83
72
const loaders = [
84
73
isEnvDevelopment && require . resolve ( 'style-loader' ) ,
85
74
isEnvProduction && {
86
75
loader : MiniCssExtractPlugin . loader ,
87
- options : shouldUseRelativeAssetPaths ? { publicPath : '../../' } : { } ,
76
+ // css is located in `static/css`, use '../../' to locate index.html folder
77
+ // in production `paths.publicUrlOrPath` can be a relative path
78
+ options : paths . publicUrlOrPath . startsWith ( '.' )
79
+ ? { publicPath : '../../' }
80
+ : { } ,
88
81
} ,
89
82
{
90
83
loader : require . resolve ( 'css-loader' ) ,
@@ -181,9 +174,10 @@ module.exports = function(webpackEnv) {
181
174
chunkFilename : isEnvProduction
182
175
? 'static/js/[name].[contenthash:8].chunk.js'
183
176
: isEnvDevelopment && 'static/js/[name].chunk.js' ,
177
+ // webpack uses `publicPath` to determine where the app is being served from.
178
+ // It requires a trailing slash, or the file assets will get an incorrect path.
184
179
// We inferred the "public path" (such as / or /my-project) from homepage.
185
- // We use "/" in development.
186
- publicPath : publicPath ,
180
+ publicPath : paths . publicUrlOrPath ,
187
181
// Point sourcemap entries to original disk location (format as URL on Windows)
188
182
devtoolModuleFilenameTemplate : isEnvProduction
189
183
? info =>
@@ -192,7 +186,7 @@ module.exports = function(webpackEnv) {
192
186
. replace ( / \\ / g, '/' )
193
187
: isEnvDevelopment &&
194
188
( info => path . resolve ( info . absoluteResourcePath ) . replace ( / \\ / g, '/' ) ) ,
195
- // Prevents conflicts when multiple Webpack runtimes (from different apps)
189
+ // Prevents conflicts when multiple webpack runtimes (from different apps)
196
190
// are used on the same page.
197
191
jsonpFunction : `webpackJsonp${ appPackageJson . name } ` ,
198
192
// this defaults to 'window', but by setting it to 'this' then
@@ -259,8 +253,8 @@ module.exports = function(webpackEnv) {
259
253
: false ,
260
254
} ,
261
255
cssProcessorPluginOptions : {
262
- preset : [ 'default' , { minifyFontValues : { removeQuotes : false } } ]
263
- }
256
+ preset : [ 'default' , { minifyFontValues : { removeQuotes : false } } ] ,
257
+ } ,
264
258
} ) ,
265
259
] ,
266
260
// Automatically split vendor and commons
@@ -278,7 +272,7 @@ module.exports = function(webpackEnv) {
278
272
} ,
279
273
} ,
280
274
resolve : {
281
- // This allows you to set a fallback for where Webpack should look for modules.
275
+ // This allows you to set a fallback for where webpack should look for modules.
282
276
// We placed these paths second because we want `node_modules` to "win"
283
277
// if there are any conflicts. This matches Node resolution mechanism.
284
278
// https://github.com/facebook/create-react-app/issues/253
@@ -319,7 +313,7 @@ module.exports = function(webpackEnv) {
319
313
} ,
320
314
resolveLoader : {
321
315
plugins : [
322
- // Also related to Plug'n'Play, but this time it tells Webpack to load its loaders
316
+ // Also related to Plug'n'Play, but this time it tells webpack to load its loaders
323
317
// from the current package.
324
318
PnpWebpackPlugin . moduleLoader ( module ) ,
325
319
] ,
@@ -549,9 +543,8 @@ module.exports = function(webpackEnv) {
549
543
// Makes some environment variables available in index.html.
550
544
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
551
545
// <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
552
- // In production, it will be an empty string unless you specify "homepage"
546
+ // It will be an empty string unless you specify "homepage"
553
547
// in `package.json`, in which case it will be the pathname of that URL.
554
- // In development, this will be an empty string.
555
548
new InterpolateHtmlPlugin ( HtmlWebpackPlugin , env . raw ) ,
556
549
// This gives some necessary context to module not found errors, such as
557
550
// the requesting resource.
@@ -569,7 +562,7 @@ module.exports = function(webpackEnv) {
569
562
// See https://github.com/facebook/create-react-app/issues/240
570
563
isEnvDevelopment && new CaseSensitivePathsPlugin ( ) ,
571
564
// If you require a missing module and then `npm install` it, you still have
572
- // to restart the development server for Webpack to discover it. This plugin
565
+ // to restart the development server for webpack to discover it. This plugin
573
566
// makes the discovery automatic so you don't have to restart.
574
567
// See https://github.com/facebook/create-react-app/issues/186
575
568
isEnvDevelopment &&
@@ -589,7 +582,7 @@ module.exports = function(webpackEnv) {
589
582
// can be used to reconstruct the HTML if necessary
590
583
new ManifestPlugin ( {
591
584
fileName : 'asset-manifest.json' ,
592
- publicPath : publicPath ,
585
+ publicPath : paths . publicUrlOrPath ,
593
586
generate : ( seed , files , entrypoints ) => {
594
587
const manifestFiles = files . reduce ( ( manifest , file ) => {
595
588
manifest [ file . name ] = file . path ;
@@ -606,19 +599,19 @@ module.exports = function(webpackEnv) {
606
599
} ,
607
600
} ) ,
608
601
// Moment.js is an extremely popular library that bundles large locale files
609
- // by default due to how Webpack interprets its code. This is a practical
602
+ // by default due to how webpack interprets its code. This is a practical
610
603
// solution that requires the user to opt into importing specific locales.
611
604
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
612
605
// You can remove this if you don't use Moment.js:
613
606
new webpack . IgnorePlugin ( / ^ \. \/ l o c a l e $ / , / m o m e n t $ / ) ,
614
607
// Generate a service worker script that will precache, and keep up to date,
615
- // the HTML & assets that are part of the Webpack build.
608
+ // the HTML & assets that are part of the webpack build.
616
609
isEnvProduction &&
617
610
new WorkboxWebpackPlugin . GenerateSW ( {
618
611
clientsClaim : true ,
619
612
exclude : [ / \. m a p $ / , / a s s e t - m a n i f e s t \. j s o n $ / ] ,
620
613
importWorkboxFrom : 'cdn' ,
621
- navigateFallback : publicUrl + '/ index.html' ,
614
+ navigateFallback : paths . publicUrlOrPath + 'index.html' ,
622
615
navigateFallbackBlacklist : [
623
616
// Exclude URLs starting with /_, as they're likely an API call
624
617
new RegExp ( '^/_' ) ,
@@ -658,7 +651,7 @@ module.exports = function(webpackEnv) {
658
651
} ) ,
659
652
] . filter ( Boolean ) ,
660
653
// Some libraries import Node modules but don't use them in the browser.
661
- // Tell Webpack to provide empty mocks for them so importing them works.
654
+ // Tell webpack to provide empty mocks for them so importing them works.
662
655
node : {
663
656
module : 'empty' ,
664
657
dgram : 'empty' ,
0 commit comments