html-bundler-webpack-plugin
Advanced tools
Comparing version 1.5.1 to 1.5.2
# Change log | ||
## 1.5.2 (2023-03-03) | ||
- fix: correct loader export when template contain CRLF line separators | ||
- fix: correct resolve `auto` value for `verbose` option | ||
## 1.5.1 (2023-03-03) | ||
@@ -4,0 +8,0 @@ - fix: add LF after each generated script tag in dev mode for pretty HTML formatting |
{ | ||
"name": "html-bundler-webpack-plugin", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"description": "HTML bundler plugin for webpack handels HTML template as entry point, extracts CSS and JS from their sources specified in HTML.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -79,3 +79,3 @@ const { minify } = require('html-minifier-terser'); | ||
const options = Options.get(); | ||
let isMinify = Options.isTrue(options.minify, false); | ||
let isMinify = Options.toBool(options.minify, true, false); | ||
let minifyOptions; | ||
@@ -82,0 +82,0 @@ |
@@ -54,2 +54,3 @@ const path = require('path'); | ||
.then((value) => { | ||
//return value; | ||
errorStage = 'compile'; | ||
@@ -56,0 +57,0 @@ return Template.compile(value, resource); |
@@ -22,4 +22,12 @@ const Resolver = require('../Resolver'); | ||
decodeReservedChars(str) { | ||
const match = /('|\\u0026|\\u0027|\\u0060|\n)/g; | ||
const replacements = { '\\u0026': '&', '\\u0027': "'", '\\u0060': "\\'", "'": "\\'", '\n': '\\n' }; | ||
const match = /('|\\u0026|\\u0027|\\u0060|\n|\r|\\)/g; | ||
const replacements = { | ||
'\\u0026': '&', | ||
'\\u0027': "'", | ||
'\\u0060': "\\'", | ||
"'": "\\'", | ||
'\n': '\\n', | ||
'\r': '\\r', | ||
'\\': '\\\\', | ||
}; | ||
const replacer = (value) => replacements[value]; | ||
@@ -26,0 +34,0 @@ |
@@ -652,5 +652,6 @@ const vm = require('vm'); | ||
let code = source.source(); | ||
let result; | ||
if (!code) { | ||
// TODO: reproduce this case and write test | ||
// TODO: reproduce this case in test | ||
// the source is empty when webpack config contains an error | ||
@@ -675,9 +676,8 @@ return null; | ||
}; | ||
const contextObject = vm.createContext(contextOptions); | ||
const script = new vm.Script(code, { filename: sourceFile }); | ||
const compiledCode = script.runInContext(contextObject) || ''; | ||
let content; | ||
try { | ||
content = isFunction(compiledCode) ? compiledCode() : compiledCode; | ||
const script = new vm.Script(code, { filename: sourceFile }); | ||
const contextObject = vm.createContext(contextOptions); | ||
const compiledCode = script.runInContext(contextObject) || ''; | ||
result = isFunction(compiledCode) ? compiledCode() : compiledCode; | ||
} catch (error) { | ||
@@ -690,3 +690,3 @@ executeTemplateFunctionException(error, sourceFile); | ||
pluginModule.inline = inline; | ||
content = pluginModule.extract(content, assetFile, this.compilation); | ||
result = pluginModule.extract(result, assetFile, this.compilation); | ||
} | ||
@@ -703,3 +703,3 @@ if (pluginModule.postprocess) { | ||
try { | ||
content = pluginModule.postprocess(content, resourceInfo, this.compilation); | ||
result = pluginModule.postprocess(result, resourceInfo, this.compilation); | ||
} catch (error) { | ||
@@ -712,7 +712,7 @@ postprocessException(error, resourceInfo); | ||
if (inline) { | ||
AssetSource.setSource(sourceRequest, this.currentEntryPoint.filename, content); | ||
AssetSource.setSource(sourceRequest, this.currentEntryPoint.filename, result); | ||
return null; | ||
} | ||
return content; | ||
return result; | ||
} | ||
@@ -719,0 +719,0 @@ |
@@ -94,3 +94,3 @@ const path = require('path'); | ||
if (module) { | ||
if (module.hasOwnProperty('verbose')) verbose = Options.isTrue(module.verbose, false); | ||
if (module.hasOwnProperty('verbose')) verbose = Options.toBool(module.verbose, false, false); | ||
if (module.filename) filenameTemplate = module.filename; | ||
@@ -97,0 +97,0 @@ if (module.sourcePath) sourcePath = module.sourcePath; |
@@ -79,5 +79,5 @@ const path = require('path'); | ||
this.prodMode = options.mode == null || options.mode === 'production'; | ||
this.verbose = this.isTrue(this.options.verbose, false); | ||
extractJs.verbose = this.isTrue(extractJs.verbose, false); | ||
extractCss.verbose = this.isTrue(extractCss.verbose, false); | ||
this.verbose = this.toBool(this.options.verbose, false, false); | ||
extractJs.verbose = this.toBool(extractJs.verbose, false, false); | ||
extractCss.verbose = this.toBool(extractCss.verbose, false, false); | ||
@@ -194,6 +194,15 @@ if (!webpackOutput.path) webpackOutput.path = path.join(this.context, 'dist'); | ||
static isTrue(value, defaultValue) { | ||
/** | ||
* Resolve undefined|true|false|'auto' value depend on current Webpack mode dev/prod. | ||
* | ||
* @param {boolean|string|undefined} value The value one of true, false, 'auto'. | ||
* @param {boolean} autoValue Returns the autoValue in prod mode when value is 'auto'. | ||
* @param {boolean} defaultValue Returns default value when value is undefined. | ||
* @return {boolean} | ||
*/ | ||
static toBool(value, autoValue, defaultValue) { | ||
if (value == null) return defaultValue; | ||
if (value === true || value === false) return value; | ||
return value === true || (this.prodMode === true && value === 'auto'); | ||
return value === 'auto' && this.prodMode === autoValue; | ||
} | ||
@@ -200,0 +209,0 @@ |
244597
4484