Skip to content

Commit 2322e97

Browse files
Support native __webpack_public_path__.
This means you don't need to set the `publicPath` option during setup and the loader will use webpack's native one. Resolves faceyspacey#51.
1 parent 4b3b0a5 commit 2322e97

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

loader.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ module.exports.pitch = function(request) {
5454
}
5555

5656
var childFilename = "extract-text-webpack-plugin-output-filename"; // eslint-disable-line no-path-concat
57-
var publicPath = typeof query.publicPath === "string" ? query.publicPath : this._compilation.outputOptions.publicPath;
57+
var publicPath = typeof query.publicPath === "string" ? query.publicPath : null;
5858
var outputOptions = {
5959
filename: childFilename,
60-
publicPath: publicPath
60+
publicPath: publicPath || this._compilation.outputOptions.publicPath,
6161
};
6262
var childCompiler = this._compilation.createChildCompiler("extract-text-webpack-plugin", outputOptions);
6363
childCompiler.apply(new NodeTemplatePlugin(outputOptions));
@@ -140,12 +140,14 @@ module.exports.pitch = function(request) {
140140
// All we need is a date that changes during dev, to trigger a reload since
141141
// hashes generated based on the file contents are what trigger HMR.
142142
if (process.env.NODE_ENV === 'development') {
143+
const pathVar = publicPath ?
144+
`"${publicPath}"` : "__wepback_public_path__";
143145
resultSource += `
144146
if (module.hot) {
145147
module.hot.accept();
146148
if (module.hot.data) {
147149
var neverUsed = ${+new Date()}
148-
require(${loaderUtils.stringifyRequest(this, path.join(__dirname, "hotModuleReplacement.js"))})("${publicPath}", "%%extracted-file%%");
150+
require(${loaderUtils.stringifyRequest(this, path.join(__dirname, "hotModuleReplacement.js"))})(${pathVar}, "%%extracted-file%%");
149151
}
150152
}`;
151153
}

0 commit comments

Comments
 (0)