Skip to content

Commit 8cc1ff1

Browse files
authored
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.
1 parent 359df9a commit 8cc1ff1

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

dist/server/build.js

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ if (_commander2.default.staticDir) {
9595
process.exit(-1);
9696
}
9797
logger.log('=> Copying static files from: ' + dir);
98-
_shelljs2.default.cp('-r', dir + '/', outputDir);
98+
_shelljs2.default.cp('-r', dir + '/*', outputDir);
9999
});
100100
}
101101

dist/server/config/utils.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ function loadEnv() {
4747

4848
var defaultNodeEnv = options.production ? 'production' : 'development';
4949
var env = {
50-
'process.env.NODE_ENV': (0, _stringify2.default)(process.env.NODE_ENV || defaultNodeEnv)
50+
'process.env.NODE_ENV': (0, _stringify2.default)(process.env.NODE_ENV || defaultNodeEnv),
51+
// This is to support CRA's public folder feature.
52+
// In production we set this to dot(.) to allow the browser to access these assests
53+
// even when deployed inside a subpath. (like in GitHub pages)
54+
// In development this is just empty as we always serves from the root.
55+
'process.env.PUBLIC_URL': (0, _stringify2.default)(options.production ? '.' : '')
5156
};
5257

5358
(0, _keys2.default)(process.env).filter(function (name) {

src/server/build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ if (program.staticDir) {
6969
process.exit(-1);
7070
}
7171
logger.log(`=> Copying static files from: ${dir}`);
72-
shelljs.cp('-r', `${dir}/`, outputDir);
72+
shelljs.cp('-r', `${dir}/*`, outputDir);
7373
});
7474
}
7575

src/server/config/utils.js

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export function loadEnv(options = {}) {
2727
const defaultNodeEnv = options.production ? 'production' : 'development';
2828
const env = {
2929
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || defaultNodeEnv),
30+
// This is to support CRA's public folder feature.
31+
// In production we set this to dot(.) to allow the browser to access these assests
32+
// even when deployed inside a subpath. (like in GitHub pages)
33+
// In development this is just empty as we always serves from the root.
34+
'process.env.PUBLIC_URL': JSON.stringify(options.production ? '.' : ''),
3035
};
3136

3237
Object.keys(process.env)

0 commit comments

Comments
 (0)