@craftamap/esbuild-plugin-html

中文文档
0.9.0发布于 2025/03/17MITCommonJS近 30 天下载 32.8万

npm

中文使用文档
文档目录7 节
  1. 所需资源
  2. 安装
  3. 使用量
  4. 样本配置
  5. 配置
  6. 捐款
  7. 库多斯: 其他 *.html - 弹簧

@ craftamap/ esbuilt- plugin- html 页面存档备份,存于互联网档案馆

npm

Simple banner containing the name of the project in a html self-closing tag

@craftamap/esbuild-plugin-html 是用来生成 HTML 文件的插件 兴建所有指定的入境点及其 相关文件(例如 .css-文件)自动被注入到 HTML 文档. @craftamap/esbuild-plugin-html 灵感来自 jantimon/html-webpack-插件。 。 。 .

缺少任何特征吗? 请造出一票.

所需资源

此插件至少需要 esbuild v0.12.26. 最小节点版本 支持为Node.js 18.

Deno 官方不支持 - 但是, 据报道插件 与德诺合作.

安装

yarn add -D @craftamap/esbuild-plugin-html
# or
npm install --save-dev @craftamap/esbuild-plugin-html

使用量

此插件通过分析 metafile 建设提供。 这个 metafile包含所有条目Point及其输出文件的信息. 这样,这个插件可以将输入文件映射到其输出文件(javascript as 以及css(英语:css).

craftamap/esbuild-plugin-html 使用该 日记 在引擎盖下从所提供的模板创建您 HTML 的模型。 单位 此模式,所有发现的资源都被注入。 该插件也使用 摇篮 模板 插入自定义用户 数据输入模板.

@craftamap/esbuild-plugin-html 需要设置一些选项 构建脚本 :

  • outdir 必须设定。 html 文件生成于 outdir。 。 。 .
  • metafile 必须设置为 true (如果是,插件会自动做到这一点) 未设置为 false (第1段).

qq: 您可以使用 esbuild 设置特定的资源输出名称 entryNames 特性。 当此插件尽量支持时 可以,它可能或可能不可靠。 如果你遇到任何问题, 请创建一张票.

样本配置

const esbuild = require('esbuild');
const { htmlPlugin } = require('@craftamap/esbuild-plugin-html');

const options = {
    entryPoints: ['src/index.jsx'],
    bundle: true,
    metafile: true, // needs to be set
    outdir: 'dist/', // needs to be set
    plugins: [
        htmlPlugin({
            files: [
                {
                    entryPoints: [
                        'src/index.jsx',
                    ],
                    filename: 'index.html',
                    htmlTemplate: `
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
            </head>
            <body>
                <div id="root">
                </div>
            </body>
            </html>
          `,
                },
                {
                    entryPoints: [
                        'src/auth/auth.jsx',
                    ],
                    filename: 'auth.html',
                    title: 'Login',
                    scriptLoading: 'module',
                    favicon: './public/favicon.ico',
                    hash: true,
                },
                {
                    entryPoints: [
                        'src/installation/installation.jsx',
                    ],
                    filename: 'installation.html',
                    title: 'title',
                    scriptLoading: 'module',
                    define: {
                        "version": "0.3.0",
                    },
                    htmlTemplate: `
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
            </head>
            <body>
                You are using version <%- define.version %>
                <div id="root">
                </div>
            </body>
            </html>
          `,
                },
            ]
        })
    ]
}

esbuild.build(options).catch(() => process.exit(1))

配置

interface Configuration {
    files: HtmlFileConfiguration[],
}

interface HtmlFileConfiguration {
    filename: string,           // Output filename, e.g. index.html. This path is relative to the out dir
    entryPoints: string[],      // Entry points to inject into the created html file, e.g. ['src/index.jsx']. 
                                // Multiple entryPoints are possible.
    title?: string,             // title to inject into the head, will not be set if not specified
    htmlTemplate?: string,      // custom html document template string. If you omit a template, 
                                // a default template will be used (see below)
                                // can also be a relative path to an html file
    define?: Record<string, string>,
                                // Define custom values that can be accessed in the lodash template context
    scriptLoading?: 'blocking' | 'defer' | 'module', 
                                // 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
    findRelatedCssFiles?: boolean,
                                // Find related output *.css-files and inject them into the html. 
                                // Defaults to true.
    findRelatedOutputFiles?: boolean,
                                // 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.
    inline?: boolean | {        // Inline all js and css entry points into the html file.
        js?: boolean,           // Inline all js resources into the html file. 
        css?: boolean,          // Inline all css resources into the html file.
    } | ((filepath: string) => boolean), // Inline resources by custom function.
                                // Not set by default - will not inline any resources.
    extraScripts?: (string | {  // accepts an array of src strings or objects with src and attributes
        src: string;            // src to use for the script
        attrs?: { [key: string]: string } // attributes to append to the script, e.g. { type: 'module', async: true }
    })[],
    hash?: boolean | string,    // Append a hash to all included scripts and CSS files for cache-busting. The
                                // hash is based on the given string. If given a boolean, the hash is based on
                                // the current time.
}

情况a publicPath 正在安装配置中指定, esbuild-plugin-html 将使用绝对路径 publicPath。 。 。 .

您也可以通过改变 Esbuild 的动词来改变插件的动词.

默认 HTML 模板

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
  </body>
</html>

捐款

捐款总是受到欢迎.

现 tsc 用于构建项目.

提交信息应当按照 常规武器委员会。 。 。 .

库多斯: 其他 *.html- 弹簧

还有其他的 *.html- 用于建造的插座。 这些工作不同 比起来 @craftamap/esbuild-plugin-html也许更适合你

版本与发布记录

@craftamap/esbuild-plugin-html 共发布 15 个版本,首次发布于 2021/09/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.9.0latest2025/03/171.7 年前
0.8.02024/08/292 年前
0.7.02024/05/142 年前
0.6.12023/07/053 年前
0.6.02023/07/053 年前
0.5.02022/12/293 年前

关于 @craftamap/esbuild-plugin-html 的常见问题

如何安装 @craftamap/esbuild-plugin-html?

在项目目录运行 npm install @craftamap/esbuild-plugin-html,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:esbuild(>=0.15.10)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@craftamap/esbuild-plugin-html 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/craftamap__esbuild-plugin-html 是否存在。

@craftamap/esbuild-plugin-html 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@craftamap/esbuild-plugin-html 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@craftamap/esbuild-plugin-html 可以商用吗?

@craftamap/esbuild-plugin-html 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@craftamap/esbuild-plugin-html 的下载量有多少?

根据 npm 官方下载统计,@craftamap/esbuild-plugin-html 在 2026/10/11 – 2026/11/09 这 30 天内被下载 328,332 次,日均约 10,944 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@craftamap/esbuild-plugin-html 还在维护吗?

最新版本 0.9.0 发布于 2025/03/17(1.7 年前);至今共发布 15 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/09/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。