Skip to content

Commit

Permalink
CRA's PUBLIC_URL support (#529)
Browse files Browse the repository at this point in the history
* Bug fix: Copy static content to the root of the export dir.
c

* Add support to PUBLIC_URL env variable.
  • Loading branch information
arunoda authored Oct 5, 2016
1 parent 359df9a commit 8cc1ff1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/server/build.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
7 changes: 6 additions & 1 deletion dist/server/config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/server/config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8cc1ff1

Please sign in to comment.