@@ -28,17 +28,20 @@ const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeM
2828const ModuleScopePlugin = require ( 'react-dev-utils/ModuleScopePlugin' ) ;
2929const getCSSModuleLocalIdent = require ( 'react-dev-utils/getCSSModuleLocalIdent' ) ;
3030// const paths = require('./paths'); // wptheme - remarked out
31+ const paths = require ( './paths-wptheme' ) ; // wptheme - added
3132const modules = require ( './modules' ) ;
3233const getClientEnvironment = require ( './env' ) ;
3334const ModuleNotFoundPlugin = require ( 'react-dev-utils/ModuleNotFoundPlugin' ) ;
3435const ForkTsCheckerWebpackPlugin = require ( 'react-dev-utils/ForkTsCheckerWebpackPlugin' ) ;
3536const typescriptFormatter = require ( 'react-dev-utils/typescriptFormatter' ) ;
37+ const eslint = require ( 'eslint' ) ;
3638// @remove -on-eject-begin
3739const getCacheIdentifier = require ( 'react-dev-utils/getCacheIdentifier' ) ;
3840// @remove -on-eject-end
3941const postcssNormalize = require ( 'postcss-normalize' ) ;
4042
41- const paths = require ( './paths-wptheme' ) ;
43+ const appPackageJson = require ( paths . appPackageJson ) ;
44+
4245const FileWatcherPlugin = require ( '@devloco/react-scripts-wptheme-utils/fileWatcherPlugin' ) ;
4346
4447const wpThemeUserConfig = require ( '@devloco/react-scripts-wptheme-utils/getUserConfig' ) (
@@ -57,6 +60,10 @@ const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
5760// makes for a smoother build process.
5861const shouldInlineRuntimeChunk = process . env . INLINE_RUNTIME_CHUNK !== 'false' ;
5962
63+ const imageInlineSizeLimit = parseInt (
64+ process . env . IMAGE_INLINE_SIZE_LIMIT || '10000'
65+ ) ;
66+
6067// Check if TypeScript is setup
6168const useTypeScript = fs . existsSync ( paths . appTsConfig ) ;
6269
@@ -147,12 +154,20 @@ module.exports = function(webpackEnv) {
147154 } ,
148155 ] . filter ( Boolean ) ;
149156 if ( preProcessor ) {
150- loaders . push ( {
151- loader : require . resolve ( preProcessor ) ,
152- options : {
153- sourceMap : isEnvProduction && shouldUseSourceMap ,
157+ loaders . push (
158+ {
159+ loader : require . resolve ( 'resolve-url-loader' ) ,
160+ options : {
161+ sourceMap : isEnvProduction && shouldUseSourceMap ,
162+ } ,
154163 } ,
155- } ) ;
164+ {
165+ loader : require . resolve ( preProcessor ) ,
166+ options : {
167+ sourceMap : true ,
168+ } ,
169+ }
170+ ) ;
156171 }
157172 return loaders ;
158173 } ;
@@ -197,13 +212,13 @@ module.exports = function(webpackEnv) {
197212 // In development, it does not produce real files.
198213 filename : isEnvProduction
199214 ? 'static/js/[name].[contenthash:8].js'
200- : isEnvDevelopment && 'static/js/[name].[contenthash:8].js' , //'static/js/bundle.js',
215+ : isEnvDevelopment && 'static/js/[name].[contenthash:8].js' , // wptheme modified... always use cache busting
201216 // TODO: remove this when upgrading to webpack 5
202217 futureEmitAssets : true ,
203218 // There are also additional JS chunk files if you use code splitting.
204219 chunkFilename : isEnvProduction
205220 ? 'static/js/[name].[contenthash:8].chunk.js'
206- : isEnvDevelopment && 'static/js/[name].[contenthash:8].chunk.js' , //'static/js/[name].chunk.js',
221+ : isEnvDevelopment && 'static/js/[name].[contenthash:8].chunk.js' , // wptheme modified... always use cache busting
207222 // We inferred the "public path" (such as / or /my-project) from homepage.
208223 // We use "/" in development.
209224 publicPath : publicPath ,
@@ -215,6 +230,9 @@ module.exports = function(webpackEnv) {
215230 . replace ( / \\ / g, '/' )
216231 : isEnvDevelopment &&
217232 ( info => path . resolve ( info . absoluteResourcePath ) . replace ( / \\ / g, '/' ) ) ,
233+ // Prevents conflicts when multiple Webpack runtimes (from different apps)
234+ // are used on the same page.
235+ jsonpFunction : `webpackJsonp${ appPackageJson . name } ` ,
218236 } ,
219237 optimization : {
220238 minimize : isEnvProduction ,
@@ -223,8 +241,8 @@ module.exports = function(webpackEnv) {
223241 new TerserPlugin ( {
224242 terserOptions : {
225243 parse : {
226- // we want terser to parse ecma 8 code. However, we don't want it
227- // to apply any minfication steps that turns valid ecma 5 code
244+ // We want terser to parse ecma 8 code. However, we don't want it
245+ // to apply any minification steps that turns valid ecma 5 code
228246 // into invalid ecma 5 code. This is why the 'compress' and 'output'
229247 // sections only apply transformations that are ecma 5 safe
230248 // https://github.com/facebook/create-react-app/pull/4234
@@ -349,10 +367,26 @@ module.exports = function(webpackEnv) {
349367 options : {
350368 formatter : require . resolve ( 'react-dev-utils/eslintFormatter' ) ,
351369 eslintPath : require . resolve ( 'eslint' ) ,
370+ resolvePluginsRelativeTo : __dirname ,
352371 // @remove -on-eject-begin
353- baseConfig : {
354- extends : [ require . resolve ( 'eslint-config-react-app' ) ] ,
355- } ,
372+ baseConfig : ( ( ) => {
373+ const eslintCli = new eslint . CLIEngine ( ) ;
374+ let eslintConfig ;
375+ try {
376+ eslintConfig = eslintCli . getConfigForFile ( paths . appIndexJs ) ;
377+ } catch ( e ) {
378+ // A config couldn't be found.
379+ }
380+
381+ // We allow overriding the config only if the env variable is set
382+ if ( process . env . EXTEND_ESLINT && eslintConfig ) {
383+ return eslintConfig ;
384+ } else {
385+ return {
386+ extends : [ require . resolve ( 'eslint-config-react-app' ) ] ,
387+ } ;
388+ }
389+ } ) ( ) ,
356390 ignore : false ,
357391 useEslintrc : false ,
358392 // @remove -on-eject-end
@@ -374,7 +408,7 @@ module.exports = function(webpackEnv) {
374408 test : [ / \. b m p $ / , / \. g i f $ / , / \. j p e ? g $ / , / \. p n g $ / ] ,
375409 loader : require . resolve ( 'url-loader' ) ,
376410 options : {
377- limit : 10000 ,
411+ limit : imageInlineSizeLimit ,
378412 name : 'static/media/[name].[hash:8].[ext]' ,
379413 } ,
380414 } ,
@@ -415,7 +449,8 @@ module.exports = function(webpackEnv) {
415449 {
416450 loaderMap : {
417451 svg : {
418- ReactComponent : '@svgr/webpack?-svgo,+ref![path]' ,
452+ ReactComponent :
453+ '@svgr/webpack?-svgo,+titleProp,+ref![path]' ,
419454 } ,
420455 } ,
421456 } ,
@@ -667,9 +702,11 @@ module.exports = function(webpackEnv) {
667702 navigateFallbackBlacklist : [
668703 // Exclude URLs starting with /_, as they're likely an API call
669704 new RegExp ( '^/_' ) ,
670- // Exclude URLs containing a dot, as they're likely a resource in
671- // public/ and not a SPA route
672- new RegExp ( '/[^/]+\\.[^/]+$' ) ,
705+ // Exclude any URLs whose last part seems to be a file extension
706+ // as they're likely a resource and not a SPA route.
707+ // URLs containing a "?" character won't be blacklisted as they're likely
708+ // a route with query params (e.g. auth callbacks).
709+ new RegExp ( '/[^/?]+\\.[^/]+$' ) ,
673710 ] ,
674711 } ) ,
675712 // TypeScript type checking
0 commit comments