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

Feature/loaders #41

Merged
merged 6 commits into from
Jan 20, 2016
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
23 changes: 23 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# appveyor file
# http://www.appveyor.com/docs/appveyor-yml

environment:
matrix:
- nodejs_version: 0.10
- nodejs_version: 0.12
- nodejs_version: 4

version: "{build}"
build: off
deploy: off
matrix:
fast_finish: true

install:
- ps: Install-Product node $env:nodejs_version
- npm install

test_script:
- node --version
- npm --version
- npm test
40 changes: 14 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,20 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) {

compiler.plugin('make', function(compilation, callback) {
// Compile the template (queued)
compilationPromise = getNextCompilationSlot(compiler, function() {
return childCompiler.compileTemplate(self.options.template, compiler.context, self.options.filename, compilation)
.catch(function(err) {
compilation.errors.push(prettyError(err, compiler.context).toString());
return {
content: self.options.showErrors ? prettyError(err, compiler.context).toJsonHtml() : 'ERROR',
};
})
.then(function(compilationResult) {
// If the compilation change didnt change the cache is valid
isCompilationCached = compilationResult.hash && self.hash === compilationResult.hash;
self.hash = compilation.hash;
callback();
return compilationResult.content;
});
});
compilationPromise = childCompiler.compileTemplate(self.options.template, compiler.context, self.options.filename, compilation)
.catch(function(err) {
compilation.errors.push(prettyError(err, compiler.context).toString());
return {
content: self.options.showErrors ? prettyError(err, compiler.context).toJsonHtml() : 'ERROR'
};
})
.then(function(compilationResult) {
// If the compilation change didnt change the cache is valid
isCompilationCached = compilationResult.hash && self.hash === compilationResult.hash;
self.hash = compilation.hash;
callback();
return compilationResult.content;
});
});

compiler.plugin('after-compile', function(compilation, callback) {
Expand Down Expand Up @@ -498,14 +496,4 @@ HtmlWebpackPlugin.prototype.getFullTemplatePath = function(template, context) {
});
};

/**
* Helper to prevent html-plugin compilation in parallel
* Fixes "No source available" where incomplete cache modules were used
*/
function getNextCompilationSlot(compiler, newEntry) {
compiler.HtmlWebpackPluginQueue = (compiler.HtmlWebpackPluginQueue || Promise.resolve())
.then(newEntry);
return compiler.HtmlWebpackPluginQueue;
}

module.exports = HtmlWebpackPlugin;
6 changes: 5 additions & 1 deletion lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ module.exports.compileTemplate = function compileTemplate(template, context, out
new SingleEntryPlugin(this.context, template),
new LoaderTargetPlugin('node')
);
childCompiler.plugin("compilation", function(compilation) {

// Fix for "Uncaught TypeError: __webpack_require__(...) is not a function"
// Hot module replacement requires that every child compiler has its own
// cache. @see https://github.com/ampedandwired/html-webpack-plugin/pull/179
childCompiler.plugin('compilation', function(compilation) {
if(compilation.cache) {
if(!compilation.cache[compilerName])
compilation.cache[compilerName] = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ module.exports = function (source) {
// Use underscore for a minimalistic loader
var options = loaderUtils.parseQuery(this.query);
var template = _.template(source, options);
return 'var _ = require("' + require.resolve('lodash') + '");module.exports = ' + template;
return 'var _ = require(' + loaderUtils.stringifyRequest(this, require.resolve('lodash')) + ');module.exports = ' + template;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-webpack-plugin",
"version": "2.6.3",
"version": "2.6.5",
"description": "Simplifies creation of HTML files to serve your webpack bundles",
"main": "index.js",
"files": [
Expand Down