From 5ee77757bd8e08ed1f92e42ced2a6e468e20bfe4 Mon Sep 17 00:00:00 2001 From: Fabian Siegel Date: Mon, 31 Jan 2022 17:48:22 +0100 Subject: [PATCH 1/2] related-files: add option to disable finding related files (#16) --- lib/cjs/index.d.ts | 1 + lib/cjs/index.js | 11 ++++++++++- src/index.ts | 13 +++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/cjs/index.d.ts b/lib/cjs/index.d.ts index fc07dd4..1bf10e6 100644 --- a/lib/cjs/index.d.ts +++ b/lib/cjs/index.d.ts @@ -10,5 +10,6 @@ export interface HtmlFileConfiguration { define?: Record; scriptLoading?: 'blocking' | 'defer' | 'module'; favicon?: string; + findRelatedOutputFiles?: boolean; } export declare const htmlPlugin: (configuration?: Configuration) => esbuild.Plugin; diff --git a/lib/cjs/index.js b/lib/cjs/index.js index 5c906eb..f2abf78 100644 --- a/lib/cjs/index.js +++ b/lib/cjs/index.js @@ -27,6 +27,9 @@ function escapeRegExp(text) { return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); } const htmlPlugin = (configuration = { files: [], }) => { + configuration.files = configuration.files.map((htmlFileConfiguration) => { + return Object.assign({}, { 'findRelatedOutputFiles': true }, htmlFileConfiguration); // Set default values + }); let logInfo = false; function collectEntrypoints(htmlFileConfiguration, metafile) { const entryPoints = Object.entries((metafile === null || metafile === void 0 ? void 0 : metafile.outputs) || {}).filter(([, value]) => { @@ -166,7 +169,13 @@ const htmlPlugin = (configuration = { files: [], }) => { if (!entrypoint) { throw new Error(`Found no match for ${htmlFileConfiguration.entryPoints}`); } - const relatedOutputFiles = findRelatedOutputFiles(entrypoint, result.metafile, build.initialOptions.entryNames); + let relatedOutputFiles; + if (htmlFileConfiguration.findRelatedOutputFiles) { + relatedOutputFiles = findRelatedOutputFiles(entrypoint, result.metafile, build.initialOptions.entryNames); + } + else { + relatedOutputFiles = [entrypoint]; + } collectedOutputFiles = [...collectedOutputFiles, ...relatedOutputFiles]; } // Note: we can safely disable this rule here, as we already asserted this in setup.onStart diff --git a/src/index.ts b/src/index.ts index 3817b3f..ac7de25 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,6 +16,7 @@ export interface HtmlFileConfiguration { define?: Record, scriptLoading?: 'blocking' | 'defer' | 'module', favicon?: string, + findRelatedOutputFiles?: boolean, } const defaultHtmlTemplate = ` @@ -41,6 +42,10 @@ function escapeRegExp(text: string): string { export const htmlPlugin = (configuration: Configuration = { files: [], }): esbuild.Plugin => { + configuration.files = configuration.files.map((htmlFileConfiguration: HtmlFileConfiguration) => { + return Object.assign({}, { 'findRelatedOutputFiles': true }, htmlFileConfiguration) // Set default values + }) + let logInfo = false function collectEntrypoints(htmlFileConfiguration: HtmlFileConfiguration, metafile?: esbuild.Metafile) { @@ -193,8 +198,12 @@ export const htmlPlugin = (configuration: Configuration = { files: [], }): esbui if (!entrypoint) { throw new Error(`Found no match for ${htmlFileConfiguration.entryPoints}`) } - - const relatedOutputFiles = findRelatedOutputFiles(entrypoint, result.metafile, build.initialOptions.entryNames) + let relatedOutputFiles + if (htmlFileConfiguration.findRelatedOutputFiles) { + relatedOutputFiles = findRelatedOutputFiles(entrypoint, result.metafile, build.initialOptions.entryNames) + } else { + relatedOutputFiles = [entrypoint] + } collectedOutputFiles = [...collectedOutputFiles, ...relatedOutputFiles] } From 7c22d451c71e3b8b24926c135831e1fff39db517 Mon Sep 17 00:00:00 2001 From: Fabian Siegel Date: Sat, 12 Mar 2022 10:58:23 +0100 Subject: [PATCH 2/2] related-files: Update README (#16) --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f40eb1e..e1056c1 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,9 @@ interface HtmlFileConfiguration { // Decide if the script tag will be inserted as blocking script tag, // with `defer=""` (default) or with `type="module"` favicon?: string, // path to favicon.ico. If not specified, no favicon will be injected + findRelatedOutputFiles?: boolean, + // Find related output (*.css)-files and inject them into the html. + // Defaults to true. } ```