+ sub-directory support for production build
This commit is contained in:
parent
07c42fb541
commit
31d599fe44
|
@ -60,10 +60,9 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node scripts/watch.js",
|
"start": "node scripts/watch.js",
|
||||||
"serve": "node scripts/watch.js",
|
"serve": "node scripts/watch.js",
|
||||||
"build": "react-app-rewired build",
|
"build": "node scripts/build.js",
|
||||||
"test": "react-app-rewired test"
|
"test": "react-app-rewired test"
|
||||||
},
|
},
|
||||||
"homepage": "./",
|
|
||||||
"config-overrides-path": "scripts/config-overrides",
|
"config-overrides-path": "scripts/config-overrides",
|
||||||
"browserslist": {
|
"browserslist": {
|
||||||
"production": [
|
"production": [
|
||||||
|
|
|
@ -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");
|
|
@ -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 = () => "./";
|
|
@ -15,31 +15,8 @@ process.on("unhandledRejection", err => {
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
// Running modifications that are shared across watch.js and build.js
|
||||||
* Rewire publicPath generator
|
require("./common");
|
||||||
*
|
|
||||||
* .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 "/";
|
|
||||||
};
|
|
||||||
|
|
||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
const paths = require("react-scripts/config/paths");
|
const paths = require("react-scripts/config/paths");
|
||||||
|
|
Loading…
Reference in New Issue