+ sub-directory support for production build

This commit is contained in:
Pogodaanton 2020-07-12 18:11:38 +02:00
parent 07c42fb541
commit 31d599fe44
4 changed files with 19 additions and 27 deletions

View File

@ -60,10 +60,9 @@
"scripts": {
"start": "node scripts/watch.js",
"serve": "node scripts/watch.js",
"build": "react-app-rewired build",
"build": "node scripts/build.js",
"test": "react-app-rewired test"
},
"homepage": "./",
"config-overrides-path": "scripts/config-overrides",
"browserslist": {
"production": [

5
scripts/build.js Normal file
View File

@ -0,0 +1,5 @@
// Running modifications that are shared across watch.js and build.js
require("./common");
// Running react-app-rewired to monkey-patch webpack-config
require("react-app-rewired/scripts/build");

11
scripts/common.js Normal file
View File

@ -0,0 +1,11 @@
/**
* Rewire publicPath generator
*
* .htaccess reroutes requests of any undefined `static` directory to the `static`
* folder found in project root. Thus, we can make `publicPath` a relative value.
*
* Preferably, the project should be written with subdirectory support in mind, as
* re-building the code because of a different directory placement is inconvenient.
*/
require("react-dev-utils/getPublicUrlOrPath");
require.cache[require.resolve("react-dev-utils/getPublicUrlOrPath")].exports = () => "./";

View File

@ -15,31 +15,8 @@ process.on("unhandledRejection", err => {
throw err;
});
/**
* Rewire publicPath generator
*
* .htaccess reroutes requests of any undefined `static` directory to the `static`
* folder found in project root. Thus, we can make `publicPath` a relative value.
*/
require("react-dev-utils/getPublicUrlOrPath");
require.cache[require.resolve("react-dev-utils/getPublicUrlOrPath")].exports = (
isEnvDevelopment,
homepage
) => {
const { URL } = require("url");
const stubDomain = "https://create-react-app.dev";
if (homepage) {
// strip last slash if exists
homepage = homepage.endsWith("/") ? homepage : homepage + "/";
// validate if `homepage` is a URL or path like and use just pathname
const validHomepagePathname = new URL(homepage, stubDomain).pathname;
return homepage.startsWith(".") ? homepage : validHomepagePathname;
}
return "/";
};
// Running modifications that are shared across watch.js and build.js
require("./common");
const fs = require("fs-extra");
const paths = require("react-scripts/config/paths");