esbuild-html-plugin
Advanced tools
+1
-13
@@ -1,2 +0,1 @@ | ||
| import { minify } from 'html-minifier'; | ||
| import { writeFile } from 'node:fs/promises'; | ||
@@ -25,14 +24,3 @@ import { dirname, join, relative } from 'node:path'; | ||
| ].join(`\n`); | ||
| await writeFile(join(outdir, outfile), minify(html, { | ||
| caseSensitive: true, | ||
| collapseWhitespace: true, | ||
| conservativeCollapse: true, | ||
| decodeEntities: true, | ||
| keepClosingSlash: true, | ||
| minifyCSS: options.minify, | ||
| minifyJS: options.minify, | ||
| removeComments: options.minify, | ||
| removeScriptTypeAttributes: true, | ||
| removeStyleLinkTypeAttributes: true, | ||
| }), { encoding: `utf-8` }); | ||
| await writeFile(join(outdir, outfile), html, { encoding: `utf-8` }); | ||
| }); | ||
@@ -39,0 +27,0 @@ }, |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AA2BpD,MAAM,UAAU,UAAU,CAAC,EACzB,OAAO,EACP,QAAQ,EACR,kBAAkB,EAClB,kBAAkB,GACA;IAClB,OAAO;QACL,IAAI,EAAE,qBAAqB;QAE3B,KAAK,CAAC,KAAK;YACT,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;YAE1C,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;YAExB,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;gBAC3B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,OAAQ,CAAC,CAAC;gBAC3D,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,GAAG,C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File } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\n\nexport interface HtmlPluginOptions {\n /**\n * The output file's name for the generated HTML. This name will be combined\n * with the `outdir` or the dirname of the `outfile` from the esbuild options.\n */\n readonly outfile: string;\n\n /**\n * The language attribute for the HTML tag.\n */\n readonly language?: string;\n\n /**\n * A function that receives the output URLs of the bundled assets and returns\n * an array of strings representing the custom head elements.\n */\n readonly createHeadElements?: (outputUrls: readonly string[]) => readonly string[];\n\n /**\n * A function that receives the output URLs of the bundled assets and returns\n * an array of strings representing the custom body elements.\n */\n readonly createBodyElements?: (outputUrls: readonly string[]) => readonly string[];\n}\n\nexport function htmlPlugin({\n outfile,\n language,\n createHeadElements,\n createBodyElements,\n}: HtmlPluginOptions): Plugin {\n return {\n name: `esbuild-html-plugin`,\n\n setup(build) {\n const { initialOptions: options } = build;\n\n options.metafile = true;\n\n build.onEnd(async (result) => {\n const outdir = options.outdir ?? dirname(options.outfile!);\n const publicPath = options.publicPath || `/`;\n\n const outputUrls = (result.metafile ? Object.keys(result.metafile.outputs) : []).map(\n (outputName) => join(publicPath, relative(outdir, outputName)),\n );\n\n const html = [\n `<!DOCTYPE html>`,\n language ? `<html lang=\"${language}\">` : `<html>`,\n `<head>`,\n ...(createHeadElements?.(outputUrls) ?? []),\n `</head>`,\n `<body>`,\n ...(createBodyElements?.(outputUrls) ?? []),\n `</body>`,\n `</html>`,\n ].join(`\\n`);\n\n await writeFile(\n join(outdir, outfile),\n minify(html, {\n caseSensitive: true,\n collapseWhitespace: true,\n conservativeCollapse: true,\n decodeEntities: true,\n keepClosingSlash: true,\n minifyCSS: options.minify,\n minifyJS: options.minify,\n removeComments: options.minify,\n removeScriptTypeAttributes: true,\n removeStyleLinkTypeAttributes: true,\n }),\n { encoding: `utf-8` },\n );\n });\n },\n };\n}\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAA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AC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;YACtE,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Plugin } from 'esbuild';\n\nimport { writeFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\n\nexport interface HtmlPluginOptions {\n /**\n * The output file's name for the generated HTML. This name will be combined\n * with the `outdir` or the dirname of the `outfile` from the esbuild options.\n */\n readonly outfile: string;\n\n /**\n * The language attribute for the HTML tag.\n */\n readonly language?: string;\n\n /**\n * A function that receives the output URLs of the bundled assets and returns\n * an array of strings representing the custom head elements.\n */\n readonly createHeadElements?: (outputUrls: readonly string[]) => readonly string[];\n\n /**\n * A function that receives the output URLs of the bundled assets and returns\n * an array of strings representing the custom body elements.\n */\n readonly createBodyElements?: (outputUrls: readonly string[]) => readonly string[];\n}\n\nexport function htmlPlugin({\n outfile,\n language,\n createHeadElements,\n createBodyElements,\n}: HtmlPluginOptions): Plugin {\n return {\n name: `esbuild-html-plugin`,\n\n setup(build) {\n const { initialOptions: options } = build;\n\n options.metafile = true;\n\n build.onEnd(async (result) => {\n const outdir = options.outdir ?? dirname(options.outfile!);\n const publicPath = options.publicPath || `/`;\n\n const outputUrls = (result.metafile ? Object.keys(result.metafile.outputs) : []).map(\n (outputName) => join(publicPath, relative(outdir, outputName)),\n );\n\n const html = [\n `<!DOCTYPE html>`,\n language ? `<html lang=\"${language}\">` : `<html>`,\n `<head>`,\n ...(createHeadElements?.(outputUrls) ?? []),\n `</head>`,\n `<body>`,\n ...(createBodyElements?.(outputUrls) ?? []),\n `</body>`,\n `</html>`,\n ].join(`\\n`);\n\n await writeFile(join(outdir, outfile), html, { encoding: `utf-8` });\n });\n },\n };\n}\n"]} |
+9
-17
| { | ||
| "name": "esbuild-html-plugin", | ||
| "version": "1.0.1", | ||
| "version": "1.1.0", | ||
| "description": "An esbuild plugin that generates an HTML file.", | ||
@@ -12,4 +12,5 @@ "repository": { | ||
| "type": "module", | ||
| "exports": "./lib/index.js", | ||
| "types": "./lib/index.d.ts", | ||
| "exports": { | ||
| ".": "./lib/index.js" | ||
| }, | ||
| "files": [ | ||
@@ -27,18 +28,9 @@ "lib" | ||
| }, | ||
| "dependencies": { | ||
| "html-minifier": "^4.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/html-minifier": "^4.0.5", | ||
| "@types/node": "^20.9.0", | ||
| "@typescript-eslint/eslint-plugin": "^6.10.0", | ||
| "@typescript-eslint/parser": "^6.10.0", | ||
| "esbuild": "^0.19.5", | ||
| "eslint": "^8.53.0", | ||
| "eslint-config-prettier": "^9.0.0", | ||
| "eslint-plugin-import": "^2.29.0", | ||
| "eslint-plugin-markdown": "^3.0.1", | ||
| "prettier": "^3.0.3", | ||
| "typescript": "^5.2.2" | ||
| "@types/node": "^20.12.12", | ||
| "onecfg-lib-eslint": "^1.1.0", | ||
| "esbuild": "^0.21.2", | ||
| "prettier": "^3.2.5", | ||
| "typescript": "^5.4.5" | ||
| } | ||
| } |
+1
-3
@@ -6,4 +6,3 @@ # esbuild-html-plugin | ||
| This esbuild plugin allows the creation of an HTML file featuring output URLs of bundled assets, | ||
| while supporting customization of head and body elements. The esbuild's `minify` option handles | ||
| minification. | ||
| while supporting customization of head and body elements. | ||
@@ -24,3 +23,2 @@ ## Installation | ||
| bundle: true, | ||
| minify: true, | ||
| outdir: `dist`, | ||
@@ -27,0 +25,0 @@ publicPath: `/static`, |
0
-100%5
-54.55%9626
-15.53%51
-19.05%93
-2.11%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed