Support webpack publicPath configuration
This commit is contained in:
parent
b0f3599d11
commit
c10e9336e4
9
index.js
9
index.js
|
|
@ -10,9 +10,10 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) {
|
|||
var self = this;
|
||||
compiler.plugin('done', function(stats) {
|
||||
var webpackStatsJson = stats.toJson();
|
||||
console.log(JSON.stringify(webpackStatsJson, null, 2));
|
||||
var templateParams = {};
|
||||
templateParams.webpack = webpackStatsJson;
|
||||
templateParams.htmlWebpackPlugin = self.htmlWebpackPluginJson(webpackStatsJson);
|
||||
templateParams.htmlWebpackPlugin = self.htmlWebpackPluginJson(compiler, webpackStatsJson);
|
||||
|
||||
var templateFile = self.options.template;
|
||||
if (!templateFile) {
|
||||
|
|
@ -23,7 +24,7 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) {
|
|||
});
|
||||
};
|
||||
|
||||
HtmlWebpackPlugin.prototype.htmlWebpackPluginJson = function(webpackStatsJson) {
|
||||
HtmlWebpackPlugin.prototype.htmlWebpackPluginJson = function(compiler, webpackStatsJson) {
|
||||
var json = {};
|
||||
json.assets = {};
|
||||
for (var chunk in webpackStatsJson.assetsByChunkName) {
|
||||
|
|
@ -34,6 +35,10 @@ HtmlWebpackPlugin.prototype.htmlWebpackPluginJson = function(webpackStatsJson) {
|
|||
// Is the main bundle always the first element?
|
||||
chunkValue = chunkValue[0];
|
||||
}
|
||||
|
||||
if (compiler.options.output.publicPath) {
|
||||
chunkValue = compiler.options.output.publicPath + chunkValue;
|
||||
}
|
||||
json.assets[chunk] = chunkValue;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,5 +93,17 @@ describe('HtmlWebpackPlugin', function() {
|
|||
}, [/<script src="index_bundle_[0-9a-f]+\.js"/], done);
|
||||
});
|
||||
|
||||
it('prepends the webpack public path to script src', function(done) {
|
||||
testHtmlPlugin({
|
||||
devtool: 'sourcemap',
|
||||
entry: path.join(__dirname, 'fixtures', 'index.js'),
|
||||
output: {
|
||||
path: OUTPUT_DIR,
|
||||
filename: 'index_bundle.js',
|
||||
publicPath: 'http://cdn.example.com/assets/'
|
||||
},
|
||||
plugins: [new HtmlWebpackPlugin()]
|
||||
}, ['<script src="http://cdn.example.com/assets/index_bundle.js"'], done);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue