CRA's PUBLIC_URL support (#529)

* Bug fix: Copy static content to the root of the export dir.
c

* Add support to PUBLIC_URL env variable.
This commit is contained in:
Arunoda Susiripala 2016-10-05 13:44:38 +05:30 committed by GitHub
parent 359df9a763
commit 8cc1ff1604
4 changed files with 13 additions and 3 deletions

2
dist/server/build.js vendored Normal file → Executable file
View File

@ -95,7 +95,7 @@ if (_commander2.default.staticDir) {
process.exit(-1);
}
logger.log('=> Copying static files from: ' + dir);
_shelljs2.default.cp('-r', dir + '/', outputDir);
_shelljs2.default.cp('-r', dir + '/*', outputDir);
});
}

View File

@ -47,7 +47,12 @@ function loadEnv() {
var defaultNodeEnv = options.production ? 'production' : 'development';
var env = {
'process.env.NODE_ENV': (0, _stringify2.default)(process.env.NODE_ENV || defaultNodeEnv)
'process.env.NODE_ENV': (0, _stringify2.default)(process.env.NODE_ENV || defaultNodeEnv),
// This is to support CRA's public folder feature.
// In production we set this to dot(.) to allow the browser to access these assests
// even when deployed inside a subpath. (like in GitHub pages)
// In development this is just empty as we always serves from the root.
'process.env.PUBLIC_URL': (0, _stringify2.default)(options.production ? '.' : '')
};
(0, _keys2.default)(process.env).filter(function (name) {

View File

@ -69,7 +69,7 @@ if (program.staticDir) {
process.exit(-1);
}
logger.log(`=> Copying static files from: ${dir}`);
shelljs.cp('-r', `${dir}/`, outputDir);
shelljs.cp('-r', `${dir}/*`, outputDir);
});
}

View File

@ -27,6 +27,11 @@ export function loadEnv(options = {}) {
const defaultNodeEnv = options.production ? 'production' : 'development';
const env = {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || defaultNodeEnv),
// This is to support CRA's public folder feature.
// In production we set this to dot(.) to allow the browser to access these assests
// even when deployed inside a subpath. (like in GitHub pages)
// In development this is just empty as we always serves from the root.
'process.env.PUBLIC_URL': JSON.stringify(options.production ? '.' : ''),
};
Object.keys(process.env)