Skip to content

Commit 8f27b30

Browse files
authored
Merge pull request #9 from devloco/3.4.0-Issue.45
3.4.0 issue.45
2 parents 59e4367 + a79b35a commit 8f27b30

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
const path = require('path');
1212
const fs = require('fs');
13-
const getPublicUrlOrPath = require('@devloco/create-react-wptheme-utils/getPublicUrlOrPath');
13+
const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath');
1414

1515
// Make sure any symlinks in the project folder are resolved:
1616
// https://github.com/facebook/create-react-app/issues/637
1717
const appDirectory = fs.realpathSync(process.cwd());
18-
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
18+
const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath);
1919

2020
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
2121
// "public path" at which the app is served.
@@ -45,7 +45,7 @@ const moduleFileExtensions = [
4545

4646
// Resolve file paths in the same order as webpack
4747
const resolveModule = (resolveFn, filePath) => {
48-
const extension = moduleFileExtensions.find(extension =>
48+
const extension = moduleFileExtensions.find((extension) =>
4949
fs.existsSync(resolveFn(`${filePath}.${extension}`))
5050
);
5151

@@ -76,7 +76,8 @@ module.exports = {
7676
};
7777

7878
// @remove-on-eject-begin
79-
const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);
79+
const resolveOwn = (relativePath) =>
80+
path.resolve(__dirname, '..', relativePath);
8081

8182
// config before eject: we're in ./node_modules/react-scripts/config/
8283
module.exports = {
@@ -140,3 +141,20 @@ if (
140141
// @remove-on-eject-end
141142

142143
module.exports.moduleFileExtensions = moduleFileExtensions;
144+
145+
// wptheme Issue 45
146+
const getUserConfig = require('@devloco/create-react-wptheme-utils/getUserConfig');
147+
const wpThemeUserConfig = getUserConfig(module.exports, process.env.NODE_ENV);
148+
149+
// wptheme Issue 45; only the PROD wpThemeUserConfig object has a "homepage" member, so this works...
150+
const wpThemeConfigHomepage =
151+
(wpThemeUserConfig && wpThemeUserConfig.homepage) ||
152+
require(resolveApp('package.json')).homepage; // ... else use the one from the package.json file.
153+
154+
const wpThemePathsHomepage = process.env.PUBLIC_URL || wpThemeConfigHomepage; // default to the create-react-app setting
155+
156+
module.exports.publicUrlOrPath = getPublicUrlOrPath(
157+
/*isEnvDevelopment*/ false, // wptheme always uses PROD paths.
158+
wpThemePathsHomepage,
159+
process.env.PUBLIC_URL
160+
);

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const sassModuleRegex = /\.module\.(scss|sass)$/;
7373

7474
// This is the production and development configuration.
7575
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
76-
module.exports = function(webpackEnv) {
76+
module.exports = function (webpackEnv) {
7777
const isEnvDevelopment = webpackEnv === 'development';
7878
const isEnvProduction = webpackEnv === 'production';
7979

@@ -196,12 +196,13 @@ module.exports = function(webpackEnv) {
196196
publicPath: paths.publicUrlOrPath,
197197
// Point sourcemap entries to original disk location (format as URL on Windows)
198198
devtoolModuleFilenameTemplate: isEnvProduction
199-
? info =>
199+
? (info) =>
200200
path
201201
.relative(paths.appSrc, info.absoluteResourcePath)
202202
.replace(/\\/g, '/')
203203
: isEnvDevelopment &&
204-
(info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
204+
((info) =>
205+
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')),
205206
// Prevents conflicts when multiple webpack runtimes (from different apps)
206207
// are used on the same page.
207208
jsonpFunction: `webpackJsonp${appPackageJson.name}`,
@@ -284,7 +285,7 @@ module.exports = function(webpackEnv) {
284285
// https://twitter.com/wSokra/status/969679223278505985
285286
// https://github.com/facebook/create-react-app/issues/5358
286287
runtimeChunk: {
287-
name: entrypoint => `runtime-${entrypoint.name}`,
288+
name: (entrypoint) => `runtime-${entrypoint.name}`,
288289
},
289290
},
290291
resolve: {
@@ -302,8 +303,8 @@ module.exports = function(webpackEnv) {
302303
// `web` extension prefixes have been added for better support
303304
// for React Native Web.
304305
extensions: paths.moduleFileExtensions
305-
.map(ext => `.${ext}`)
306-
.filter(ext => useTypeScript || !ext.includes('ts')),
306+
.map((ext) => `.${ext}`)
307+
.filter((ext) => useTypeScript || !ext.includes('ts')),
307308
alias: {
308309
// Support React Native Web
309310
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
@@ -643,7 +644,7 @@ module.exports = function(webpackEnv) {
643644
// wptheme added FileWatcherPlugin
644645
// For create-react-wptheme: watch addition files in the public folder for changes
645646
// touchFile is used to force WebPack to do a rebuild. It must be a file that WebPack is watching.
646-
new FileWatcherPlugin(fileWatcherPluginConfig),
647+
isEnvDevelopment && new FileWatcherPlugin(fileWatcherPluginConfig),
647648
// If you require a missing module and then `npm install` it, you still have
648649
// to restart the development server for webpack to discover it. This plugin
649650
// makes the discovery automatic so you don't have to restart.
@@ -674,7 +675,7 @@ module.exports = function(webpackEnv) {
674675
return manifest;
675676
}, seed);
676677
const entrypointFiles = entrypoints.main.filter(
677-
fileName => !fileName.endsWith('.map')
678+
(fileName) => !fileName.endsWith('.map')
678679
);
679680

680681
return {

packages/react-scripts/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devloco/react-scripts-wptheme",
3-
"version": "3.4.0-wp.1",
3+
"version": "3.4.0-wp.9",
44
"description": "Configuration and scripts for Create React WP Theme.",
55
"repository": {
66
"type": "git",
@@ -94,7 +94,7 @@
9494
"webpack-dev-server": "3.10.2",
9595
"webpack-manifest-plugin": "2.2.0",
9696
"workbox-webpack-plugin": "4.3.1",
97-
"@devloco/create-react-wptheme-utils": "^3.4.0-wp.1"
97+
"@devloco/create-react-wptheme-utils": "^3.4.0-wp.11"
9898
},
9999
"devDependencies": {
100100
"react": "^16.12.0",

0 commit comments

Comments
 (0)