html-webpack-plugin
Advanced tools
Comparing version 5.0.0-alpha.16 to 5.0.0-alpha.17
52
index.js
@@ -115,3 +115,3 @@ // @ts-check | ||
*/ | ||
evaluateCompilationResult (source, templateFilename) { | ||
evaluateCompilationResult (source, publicPath, templateFilename) { | ||
if (!source) { | ||
@@ -126,3 +126,3 @@ return Promise.reject(new Error('The child compilation didn\'t provide a result')); | ||
const templateWithoutLoaders = templateFilename.replace(/^.+!/, '').replace(/\?.+$/, ''); | ||
const vmContext = vm.createContext({ HTML_WEBPACK_PLUGIN: true, require: require, ...global }); | ||
const vmContext = vm.createContext({ HTML_WEBPACK_PLUGIN: true, require: require, htmlWebpackPluginPublicPath: publicPath, ...global }); | ||
const vmScript = new vm.Script(source, { filename: templateWithoutLoaders }); | ||
@@ -252,5 +252,8 @@ // Evaluate code and cast to string | ||
// Turn the entry point names into file paths | ||
const assets = htmlWebpackPluginAssets(compilation, childCompilationOutputName, sortedEntryNames, options.publicPath); | ||
/** The public path used inside the html file */ | ||
const htmlPublicPath = getPublicPath(compilation, childCompilationOutputName, options.publicPath); | ||
/** Generated file paths from the entry point names */ | ||
const assets = htmlWebpackPluginAssets(compilation, sortedEntryNames, htmlPublicPath); | ||
// If the template and the assets did not change we don't have to emit the html | ||
@@ -325,6 +328,5 @@ const newAssetJson = JSON.stringify(getAssetFiles(assets)); | ||
return ('compiledEntry' in templateResult) | ||
? plugin.evaluateCompilationResult(templateResult.compiledEntry.content, options.template) | ||
? plugin.evaluateCompilationResult(templateResult.compiledEntry.content, htmlPublicPath, options.template) | ||
: Promise.reject(new Error('Child compilation contained no compiledEntry')); | ||
}); | ||
const templateExectutionPromise = Promise.all([assetsPromise, assetTagGroupsPromise, templateEvaluationPromise]) | ||
@@ -547,16 +549,11 @@ // Execute the template | ||
/** | ||
* The htmlWebpackPluginAssets extracts the asset information of a webpack compilation | ||
* for all given entry names | ||
* Generate the relative or absolute base url to reference images, css, and javascript files | ||
* from within the html file - the publicPath | ||
* | ||
* @param {WebpackCompilation} compilation | ||
* @param {string[]} entryNames | ||
* @param {string} childCompilationOutputName | ||
* @param {string | 'auto'} customPublicPath | ||
* @returns {{ | ||
publicPath: string, | ||
js: Array<string>, | ||
css: Array<string>, | ||
manifest?: string, | ||
favicon?: string | ||
}} | ||
* @returns {string} | ||
*/ | ||
function htmlWebpackPluginAssets (compilation, childCompilationOutputName, entryNames, customPublicPath) { | ||
function getPublicPath (compilation, childCompilationOutputName, customPublicPath) { | ||
const compilationHash = compilation.hash; | ||
@@ -590,2 +587,21 @@ | ||
return publicPath; | ||
} | ||
/** | ||
* The htmlWebpackPluginAssets extracts the asset information of a webpack compilation | ||
* for all given entry names | ||
* @param {WebpackCompilation} compilation | ||
* @param {string[]} entryNames | ||
* @param {string | 'auto'} publicPath | ||
* @returns {{ | ||
publicPath: string, | ||
js: Array<string>, | ||
css: Array<string>, | ||
manifest?: string, | ||
favicon?: string | ||
}} | ||
*/ | ||
function htmlWebpackPluginAssets (compilation, entryNames, publicPath) { | ||
const compilationHash = compilation.hash; | ||
/** | ||
@@ -602,3 +618,3 @@ * @type {{ | ||
// The public path | ||
publicPath: publicPath, | ||
publicPath, | ||
// Will contain all js and mjs files | ||
@@ -605,0 +621,0 @@ js: [], |
@@ -91,5 +91,3 @@ // @ts-check | ||
filename: '__child-[name]', | ||
publicPath: mainCompilation.outputOptions.publicPath === 'auto' | ||
? '' | ||
: mainCompilation.outputOptions.publicPath, | ||
publicPath: '', | ||
library: { | ||
@@ -120,2 +118,3 @@ type: 'var', | ||
this.templates.forEach((template, index) => { | ||
new EntryPlugin(childCompiler.context, 'data:text/javascript,__webpack_public_path__ = htmlWebpackPluginPublicPath;', `HtmlWebpackPlugin_${index}-${this.id}`).apply(childCompiler); | ||
new EntryPlugin(childCompiler.context, template, `HtmlWebpackPlugin_${index}-${this.id}`).apply(childCompiler); | ||
@@ -122,0 +121,0 @@ }); |
{ | ||
"name": "html-webpack-plugin", | ||
"version": "5.0.0-alpha.16", | ||
"version": "5.0.0-alpha.17", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Simplifies creation of HTML files to serve your webpack bundles", |
142352
2156