Fix context
This commit is contained in:
parent
df2e4728ab
commit
e566dac40d
26
index.js
26
index.js
|
|
@ -24,16 +24,6 @@ function HtmlWebpackPlugin(options) {
|
|||
excludeChunks: [],
|
||||
title: 'Webpack App'
|
||||
}, options);
|
||||
// If the template doesn't use a loader use the lodash template loader
|
||||
if(this.options.template.indexOf('!') === -1) {
|
||||
this.options.template = require.resolve('./lib/loader.js') + '!' + path.resolve(this.options.template);
|
||||
}
|
||||
// Resolve template path
|
||||
this.options.template = this.options.template.replace(
|
||||
/(\!)([^\/\\][^\!\?]+|[^\/\\!?])($|\?.+$)/,
|
||||
function(match, prefix, filepath, postfix) {
|
||||
return prefix + path.resolve(filepath) + postfix;
|
||||
});
|
||||
}
|
||||
|
||||
HtmlWebpackPlugin.prototype.apply = function(compiler) {
|
||||
|
|
@ -41,6 +31,8 @@ HtmlWebpackPlugin.prototype.apply = function(compiler) {
|
|||
var isCompilationCached = false;
|
||||
var compilationPromise;
|
||||
|
||||
this.options.template = this.getFullTemplatePath(this.options.template, compiler.context);
|
||||
|
||||
compiler.plugin('make', function(compilation, callback) {
|
||||
// Compile the template (queued)
|
||||
compilationPromise = getNextCompilationSlot(compiler, function() {
|
||||
|
|
@ -258,6 +250,7 @@ HtmlWebpackPlugin.prototype.postProcessHtml = function(html, assets) {
|
|||
* Pushes the content of the given filename to the compilation assets
|
||||
*/
|
||||
HtmlWebpackPlugin.prototype.addFileToAssets = function(filename, compilation) {
|
||||
filename = path.resolve(compilation.compiler.context, filename);
|
||||
return Promise.props({
|
||||
size: fs.statAsync(filename),
|
||||
source: fs.readFileAsync(filename)
|
||||
|
|
@ -492,6 +485,19 @@ HtmlWebpackPlugin.prototype.appendHash = function (url, hash) {
|
|||
return url + (url.indexOf('?') === -1 ? '?' : '&') + hash;
|
||||
};
|
||||
|
||||
HtmlWebpackPlugin.prototype.getFullTemplatePath = function(template, context) {
|
||||
// If the template doesn't use a loader use the lodash template loader
|
||||
if(template.indexOf('!') === -1) {
|
||||
template = require.resolve('./lib/loader.js') + '!' + path.resolve(context, template);
|
||||
}
|
||||
// Resolve template path
|
||||
return template.replace(
|
||||
/(\!)([^\/\\][^\!\?]+|[^\/\\!?])($|\?.+$)/,
|
||||
function(match, prefix, filepath, postfix) {
|
||||
return prefix + path.resolve(filepath) + postfix;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper to prevent html-plugin compilation in parallel
|
||||
* Fixes "No source available" where incomplete cache modules were used
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
'use strict';
|
||||
var Promise = require('bluebird');
|
||||
var path = require('path');
|
||||
var webpack = require('webpack');
|
||||
var NodeTemplatePlugin = require('webpack/lib/node/NodeTemplatePlugin');
|
||||
var NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin');
|
||||
var LoaderTargetPlugin = require('webpack/lib/LoaderTargetPlugin');
|
||||
|
|
@ -43,6 +42,7 @@ module.exports.compileTemplate = function compileTemplate(template, context, out
|
|||
// This allows us to use loaders during the compilation
|
||||
var compilerName = getCompilerName(context, outputFilename);
|
||||
var childCompiler = compilation.createChildCompiler(compilerName, outputOptions);
|
||||
childCompiler.context = context;
|
||||
childCompiler.apply(
|
||||
new NodeTemplatePlugin(outputOptions),
|
||||
new NodeTargetPlugin(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue