diff --git a/lib/cjs/index.js b/lib/cjs/index.js index e7abaee..6e064ce 100644 --- a/lib/cjs/index.js +++ b/lib/cjs/index.js @@ -94,17 +94,12 @@ const htmlPlugin = (configuration = { files: [], }) => { }); } } - async function renderTemplate({ htmlTemplate, define }, log) { - const templateContext = { define }; + async function renderTemplate({ htmlTemplate, define }) { const template = (htmlTemplate && fs_1.default.existsSync(htmlTemplate) ? await fs_1.default.promises.readFile(htmlTemplate) : htmlTemplate || '').toString(); - const isValid = template.startsWith(''); - if (log && htmlTemplate && !isValid) { - console.warn(`Warning: The htmlTemplate prop "${htmlTemplate}" does not reference a valid file`); - } - const compiledTemplateFn = (0, lodash_template_1.default)(isValid ? template : defaultHtmlTemplate); - return compiledTemplateFn(templateContext); + const compiledTemplateFn = (0, lodash_template_1.default)(template || defaultHtmlTemplate); + return compiledTemplateFn({ define }); } // use the same joinWithPublicPath function as esbuild: // https://github.com/evanw/esbuild/blob/a1ff9d144cdb8d50ea2fa79a1d11f43d5bd5e2d8/internal/bundler/bundler.go#L533 @@ -208,7 +203,7 @@ const htmlPlugin = (configuration = { files: [], }) => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const outdir = build.initialOptions.outdir; const publicPath = build.initialOptions.publicPath; - const templatingResult = await renderTemplate(htmlFileConfiguration, Boolean(build.initialOptions.logLevel)); + const templatingResult = await renderTemplate(htmlFileConfiguration); // Next, we insert the found files into the htmlTemplate - if no htmlTemplate was specified, we default to a basic one. const dom = new jsdom_1.JSDOM(templatingResult); const document = dom.window.document; diff --git a/src/index.ts b/src/index.ts index 14a6b8f..b66f85c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -119,18 +119,12 @@ export const htmlPlugin = (configuration: Configuration = { files: [], }): esbui } } - async function renderTemplate({ htmlTemplate, define }: HtmlFileConfiguration, log: boolean) { - const templateContext = { define } + async function renderTemplate({ htmlTemplate, define }: HtmlFileConfiguration) { const template = (htmlTemplate && fs.existsSync(htmlTemplate) ? await fs.promises.readFile(htmlTemplate) : htmlTemplate || '').toString() - const isValid = template.startsWith('') - - if (log && htmlTemplate && !isValid) { - console.warn(`Warning: The htmlTemplate prop "${htmlTemplate}" does not reference a valid file`) - } - const compiledTemplateFn = lodashTemplate(isValid ? template : defaultHtmlTemplate) - return compiledTemplateFn(templateContext) + const compiledTemplateFn = lodashTemplate(template || defaultHtmlTemplate) + return compiledTemplateFn({ define }) } // use the same joinWithPublicPath function as esbuild: @@ -243,7 +237,7 @@ export const htmlPlugin = (configuration: Configuration = { files: [], }): esbui const publicPath = build.initialOptions.publicPath - const templatingResult = await renderTemplate(htmlFileConfiguration, Boolean(build.initialOptions.logLevel)) + const templatingResult = await renderTemplate(htmlFileConfiguration) // Next, we insert the found files into the htmlTemplate - if no htmlTemplate was specified, we default to a basic one. const dom = new JSDOM(templatingResult)