Skip to content

Commit 9dfaa3b

Browse files
committed
Update webpack config and index.php for 3.1.1
1 parent baceeb2 commit 9dfaa3b

File tree

2 files changed

+66
-24
lines changed

2 files changed

+66
-24
lines changed

packages/react-scripts/config/webpack.config.wptheme.js

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeM
2828
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
2929
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
3030
// const paths = require('./paths'); // wptheme - remarked out
31+
const paths = require('./paths-wptheme'); // wptheme - added
3132
const modules = require('./modules');
3233
const getClientEnvironment = require('./env');
3334
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
3435
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
3536
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
37+
const eslint = require('eslint');
3638
// @remove-on-eject-begin
3739
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
3840
// @remove-on-eject-end
3941
const postcssNormalize = require('postcss-normalize');
4042

41-
const paths = require('./paths-wptheme');
43+
const appPackageJson = require(paths.appPackageJson);
44+
4245
const FileWatcherPlugin = require('@devloco/react-scripts-wptheme-utils/fileWatcherPlugin');
4346

4447
const 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.
5861
const 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
6168
const 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: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
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

packages/react-scripts/template/public/post_installer.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
<!DOCTYPE html>
55
<html lang="en">
66
<head>
7-
<meta charset="utf-8">
8-
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
9-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
10-
<meta name="theme-color" content="#000000">
7+
<meta charset="utf-8" />
8+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1" />
10+
<meta name="theme-color" content="#000000" />
11+
<meta
12+
name="description"
13+
content="Web site created using create-react-wptheme"
14+
/>
15+
<link rel="apple-touch-icon" href="logo192.png" />
1116
<!--
12-
manifest.json provides metadata used when your web app is added to the
13-
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
17+
manifest.json provides metadata used when your web app is installed on a
18+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
1419
-->
1520
<link rel="manifest" href="<?php echo $TEMPLATE_PATH; ?>/manifest.json">
1621
<!--

0 commit comments

Comments
 (0)