Expose webpack configuration to templates
This commit is contained in:
parent
51c0b876dd
commit
6ae0e85202
|
|
@ -87,7 +87,9 @@
|
|||
// jasmine helpers
|
||||
"expect": false,
|
||||
"describe": false,
|
||||
"ddescribe": false,
|
||||
"beforeEach": false,
|
||||
"it": false
|
||||
"it": false,
|
||||
"iit": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,3 +185,6 @@ template is rendered. This variable has the following attributes:
|
|||
object. Note that this is the stats object as it was at the time the HTML template
|
||||
was emitted and as such may not have the full set of stats that are available
|
||||
after the wepback run is complete.
|
||||
|
||||
- `webpackConfig`: the webpack configuration that was used for this compilation. This
|
||||
can be used, for example, to get the `publicPath` (`webpackConfig.output.publicPath`).
|
||||
|
|
|
|||
2
index.js
2
index.js
|
|
@ -17,8 +17,10 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) {
|
|||
templateParams.htmlWebpackPlugin.assets = self.htmlWebpackPluginLegacyAssets(compilation, webpackStatsJson);
|
||||
templateParams.htmlWebpackPlugin.files = self.htmlWebpackPluginAssets(compilation, webpackStatsJson);
|
||||
templateParams.htmlWebpackPlugin.options = self.options;
|
||||
|
||||
// If the hash option is true append the webpack hash to all assets
|
||||
templateParams.htmlWebpackPlugin.querystring = self.options.hash ? '?' + webpackStatsJson.hash : '';
|
||||
templateParams.webpackConfig = compilation.options;
|
||||
|
||||
var outputFilename = self.options.filename || 'index.html';
|
||||
|
||||
|
|
|
|||
|
|
@ -284,4 +284,19 @@ describe('HtmlWebpackPlugin', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('exposes the webpack configuration to templates', function(done) {
|
||||
testHtmlPlugin({
|
||||
entry: {
|
||||
app: path.join(__dirname, 'fixtures/index.js')
|
||||
},
|
||||
output: {
|
||||
path: OUTPUT_DIR,
|
||||
publicPath: 'https://cdn.com',
|
||||
filename: '[name]_bundle.js'
|
||||
},
|
||||
plugins: [new HtmlWebpackPlugin({template: path.join(__dirname, 'fixtures/webpackconfig.html')})]
|
||||
},
|
||||
['Public path is https://cdn.com'], null, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
|
||||
<title>Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Public path is {%=o.webpackConfig.output.publicPath%}</p>
|
||||
<script src="{%=o.htmlWebpackPlugin.files.chunks.app.entry%}"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue