Give devs more options for dynamically setting publicPath

This commit is contained in:
QWp6t
2017-01-09 16:22:23 -08:00
parent d06e72e20c
commit bdaf038248
4 changed files with 31 additions and 19 deletions

View File

@@ -31,15 +31,27 @@ const config = mergeWithConcat({
config.watch.push(`${path.basename(config.paths.assets)}/${config.copy}`);
config.watch = uniq(config.watch);
Object.keys(config.entry).forEach(id =>
config.entry[id].unshift(path.join(__dirname, 'public-path.js')));
module.exports = mergeWithConcat(config, {
env: Object.assign({ production: isProduction, development: !isProduction }, argv.env),
publicPath: `${config.publicPath}/${path.basename(config.paths.dist)}/`,
manifest: {},
});
if (config.enabled.watcher && !process.env.WEBPACK_PUBLIC_PATH) {
process.env.WEBPACK_PUBLIC_PATH = config.publicPath;
/**
* If your publicPath differs between environments, but you know it at compile time,
* then set SAGE_DIST_PATH as an environment variable before compiling.
* Example:
* SAGE_DIST_PATH=/wp-content/themes/sage/dist yarn build:production
*/
if (process.env.SAGE_DIST_PATH) {
module.exports.publicPath = process.env.SAGE_DIST_PATH;
}
/**
* If you don't know your publicPath at compile time, then uncomment the lines
* below and use WordPress's wp_localize_script() to set SAGE_DIST_PATH global.
* Example:
* wp_localize_script('sage/main.js', 'SAGE_DIST_PATH', get_theme_file_uri('dist/'))
*/
// Object.keys(module.exports.entry).forEach(id =>
// module.exports.entry[id].unshift(path.join(__dirname, 'public-path.js')));