@craftamap/esbuild-plugin-html
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -13,2 +13,3 @@ import esbuild from 'esbuild'; | ||
favicon?: string; | ||
findRelatedCssFiles?: boolean; | ||
findRelatedOutputFiles?: boolean; | ||
@@ -15,0 +16,0 @@ extraScripts?: (string | { |
@@ -39,3 +39,3 @@ "use strict"; | ||
configuration.files = configuration.files.map((htmlFileConfiguration) => { | ||
return Object.assign({}, { 'findRelatedOutputFiles': true }, htmlFileConfiguration); // Set default values | ||
return Object.assign({}, { findRelatedOutputFiles: false, findRelatedCssFiles: true }, htmlFileConfiguration); // Set default values | ||
}); | ||
@@ -55,3 +55,3 @@ let logInfo = false; | ||
} | ||
function findRelatedOutputFiles(entrypoint, metafile, entryNames) { | ||
function findNameRelatedOutputFiles(entrypoint, metafile, entryNames) { | ||
var _a, _b; | ||
@@ -195,10 +195,15 @@ const pathOfMatchedOutput = path_1.default.parse(entrypoint.path); | ||
} | ||
let relatedOutputFiles; | ||
const relatedOutputFiles = new Map(); | ||
relatedOutputFiles.set(entrypoint.path, entrypoint); | ||
if (htmlFileConfiguration.findRelatedCssFiles) { | ||
if (entrypoint === null || entrypoint === void 0 ? void 0 : entrypoint.cssBundle) { | ||
relatedOutputFiles.set(entrypoint.cssBundle, { path: entrypoint === null || entrypoint === void 0 ? void 0 : entrypoint.cssBundle }); | ||
} | ||
} | ||
if (htmlFileConfiguration.findRelatedOutputFiles) { | ||
relatedOutputFiles = findRelatedOutputFiles(entrypoint, result.metafile, build.initialOptions.entryNames); | ||
findNameRelatedOutputFiles(entrypoint, result.metafile, build.initialOptions.entryNames).forEach((item) => { | ||
relatedOutputFiles.set(item.path, item); | ||
}); | ||
} | ||
else { | ||
relatedOutputFiles = [entrypoint]; | ||
} | ||
collectedOutputFiles = [...collectedOutputFiles, ...relatedOutputFiles]; | ||
collectedOutputFiles = [...collectedOutputFiles, ...relatedOutputFiles.values()]; | ||
} | ||
@@ -222,3 +227,7 @@ // Note: we can safely disable this rule here, as we already asserted this in setup.onStart | ||
linkTag.setAttribute('rel', 'icon'); | ||
linkTag.setAttribute('href', '/favicon.ico'); | ||
let faviconPublicPath = '/favicon.ico'; | ||
if (publicPath) { | ||
faviconPublicPath = joinWithPublicPath(publicPath, 'favicon.ico'); | ||
} | ||
linkTag.setAttribute('href', faviconPublicPath); | ||
document.head.appendChild(linkTag); | ||
@@ -225,0 +234,0 @@ } |
{ | ||
"name": "@craftamap/esbuild-plugin-html", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"main": "./lib/cjs/index.js", | ||
@@ -19,3 +19,3 @@ "repository": { | ||
"peerDependencies": { | ||
"esbuild": ">=0.12.28" | ||
"esbuild": ">=0.15.10" | ||
}, | ||
@@ -29,3 +29,3 @@ "devDependencies": { | ||
"@typescript-eslint/parser": "^5.10.1", | ||
"esbuild": "^0.12.28", | ||
"esbuild": "^0.15.10", | ||
"eslint": "^8.8.0", | ||
@@ -32,0 +32,0 @@ "typescript": "^4.5.5" |
@@ -153,5 +153,10 @@ # @craftamap/esbuild-plugin-html | ||
favicon?: string, // path to favicon.ico. If not specified, no favicon will be injected | ||
findRelatedCssFiles?: boolean, | ||
// Find related output *.css-files and inject them into the html. | ||
// Defaults to true. | ||
findRelatedOutputFiles?: boolean, | ||
// Find related output (*.css)-files and inject them into the html. | ||
// Defaults to true. | ||
// Find output files following the same name schema of the output file | ||
// like (*.css)-files and inject them into the html. This option is deprecated, | ||
// consider using findRelatedCssFiles. | ||
// Defaults to false. | ||
extraScripts?: (string | { // accepts an array of src strings or objects with src and attributes | ||
@@ -158,0 +163,0 @@ src: string; // src to use for the script |
22921
267
215