# @xysfe/rollup-plugin-auto-html

> Rollup plugin to auto inject script into html file

Latest version **0.0.5** (published 2026-09-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @xysfe/rollup-plugin-auto-html
pnpm add @xysfe/rollup-plugin-auto-html
yarn add @xysfe/rollup-plugin-auto-html
bun add @xysfe/rollup-plugin-auto-html
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2026-09-03 |
| First published | 2021-03-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | @xysfe |
| Maintainers | mucfe |
| Keywords | rollup, rollup-plugin, auto-html |

## Links

- npm: https://www.npmjs.com/package/@xysfe/rollup-plugin-auto-html
- npm.io page: https://npm.io/package/@xysfe/rollup-plugin-auto-html

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 0.0.5 (latest) — 2026-09-03
- 0.0.4 — 2021-05-12
- 0.0.3 — 2021-03-26
- 0.0.2 — 2021-03-23
- 0.0.1 — 2021-03-22

## README

# rollup-plugin-auto-html

## 下载

```bash
npm i @xysfe/rollup-plugin-auto-html -D
```

## 使用方式
**rollup.config.js**

```js
import html from '@xysfe/rollup-plugin-auto-html'

const configMap = {
  'app': {
    prefix: 'public/h5/',
    htmlName: 'appjs',
    templatePath: '',
  },
  'tongji': {
    prefix: '',
    templatePath: ''
  },
  'gb750': {
    prefix: 'public/h5/'
  }
}

const config = [
  {
    plugins: [
      html({ configMap, env: process.env.NODE_ENV })
    ]
  }
]
```

## 注意事项
1. 插件强依赖于**NODE_ENV**环境变量，用于处理线上发布后会导致测试环境资源不可访问的现状，若没有该变量则会退出构建。**正式环境的NODE_ENV必须是production，否则无法构建出正确的资源路径。**

    NODE_ENV环境变量注入方式:
    ```json
    // file: package.json
    "scripts": {
      "dev": "cross-env NODE_ENV=development npm run bundle",
      "dist": "cross-env NODE_ENV=production npm run bundle"
    }
    ```

2. 如果不传入`configMap`配置项，插件将不会生成html文件，该配置项的每一个key值，都对应着一个html文件

## 功能

该插件会生成html文件，并将打包后的文件以标签的形式引入html文件，效果如下：

![示例图片1](./example1.jpg)

![示例图片2](./example2.jpg)


## 配置项

|  Name  | Type  |  Default  | Description  |
|  ----  | ----  |  ----  | ----  |
| configMap  | {Object} | {}  | 生成html文件的配置 |
| env  | {String} | undefined  | 环境变量 |
| prefixDir  | {String} | ''  | 资源引用路径的目录前缀，拼接于 `${cdn}/` 与产物目录之间 |

**注意：configMap配置项的`key`值，应为文件入口名。**

### configMap配置选项

|  Name  | Type  |  Default  | Description  |
|  ----  | ----  |  ----  | ----  |
| prefix  | {String} | ''  | 生成html文件的目录前缀 | 
| htmlName  | {String} | ''  | 生成html文件的文件名 | 
| templatePath  | {String} | ''  | 模板文件的路径，会在标签前插入模板文件的内容 |

---
_Source: https://npm.io/package/@xysfe/rollup-plugin-auto-html · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
