Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional compilation property to the templateParam object #246

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ HtmlWebpackPlugin.prototype.executeTemplate = function (templateFunction, chunks
htmlWebpackPlugin: {
files: assets,
options: self.options
}
},
compilation: compilation
};
var html = '';
try {
Expand Down
6 changes: 3 additions & 3 deletions migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ module.exports = '<html>...</html>';
```
More advanced template.js
```js
module.exports = function(compilationResult, chunks, assets, compilation) {
module.exports = function(templateParams) {
return '<html>..</html>';
};
```
Using loaders inside a template.js
```js
// This function has to return a string or promised string:
module.exports = function(compilationResult, chunks, assets, compilation) {
module.exports = function(templateParams) {
// Play around with the arguments and then use the webpack jade loader to load the jade:
return require('./template.jade')({assets: assets});
return require('./template.jade')({assets: templateParams.htmlWebpackPlugin.files});
};
```

Expand Down
16 changes: 16 additions & 0 deletions spec/HtmlWebpackPluginSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1047,4 +1047,20 @@ describe('HtmlWebpackPlugin', function () {
}, [
/<script src="common_bundle.js">.+<script src="aTheme_bundle.js">.+<script src="util_bundle.js">/], null, done);
});

it('should add the webpack compilation object as a property of the templateParam object', function (done) {
testHtmlPlugin({
entry: path.join(__dirname, 'fixtures/index.js'),
output: {
path: OUTPUT_DIR,
filename: 'index_bundle.js'
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, 'fixtures/templateParam.js'),
inject: false
})
]
}, ['templateParams.compilation exists: true'], null, done);
});
});
3 changes: 3 additions & 0 deletions spec/fixtures/templateParam.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (templateParams) {
return 'templateParams.compilation exists: ' + !!templateParams.compilation;
};