@auioc/rollup-plugin-html 0.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AUIOC.ORG
4
+ Copyright (c) 2022-2026 PCC-Studio
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,9 +1,168 @@
1
1
  # @auioc/rollup-plugin-html
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
3
+ [![License](https://img.shields.io/github/license/auioc/rollup-plugins?style=flat-square)](https://github.com/auioc/rollup-plugins/blob/main/packages/html/LICENSE)
4
+ [![NPM Version](https://img.shields.io/npm/v/%40auioc%2Frollup-plugin-html?style=flat-square&logo=npm)](https://www.npmjs.com/package/@auioc/rollup-plugin-html)
4
5
 
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
6
+ A Rollup plugin that generates an HTML file from a template, automatically injecting bundled JavaScript and CSS assets.
6
7
 
7
- This is **NOT** a functional package and contains **NO** code.
8
+ Supports external assets, placeholders, conditional stripping, and optional HTML minification.
8
9
 
9
- **Maintained for OIDC setup purposes only**
10
+ ## Install
11
+
12
+ ```sh
13
+ npm install --save-dev @auioc/rollup-plugin-html
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```js
19
+ // rollup.config.js
20
+ import html from '@auioc/rollup-plugin-html';
21
+
22
+ export default {
23
+ input: 'src/index.js',
24
+ output: { file: 'bundle.js', format: 'iife', name: 'bundle' },
25
+ plugins: [
26
+ html({
27
+ template: 'src/index.html',
28
+ }),
29
+ ],
30
+ };
31
+ ```
32
+
33
+ ## Options
34
+
35
+ | Option | Type | Default | Description |
36
+ | ---------------------- | --------------------------------------- | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
37
+ | `template` | `string` | | **Required**. Path to the template `.html` file, resolved relative to `process.cwd()`. |
38
+ | `output` | `string` | `'index.html'` | Output file name of the emitted HTML file. |
39
+ | `injectStyle` | `boolean` | `true` | Whether to inject styles. |
40
+ | `injectScript` | `boolean` \| `'module'` | `true` | Whether to inject scripts. Use `'module'` to add `type="module"`. |
41
+ | `external` | `{ style?: Asset[]; script?: Asset[] }` | `{ }` | External assets to inject. Their tags are placed before the bundled ones. |
42
+ | `styleTagPlaceholder` | `string` | `'<!-- inject:style -->'` | Placeholder comment replaced by CSS tags. |
43
+ | `scriptTagPlaceholder` | `string` | `'<!-- inject:script -->'` | Placeholder comment replaced by script tags. |
44
+ | `stripTag` | `string` | `'strip'` | Tag name used for strip comment blocks. |
45
+ | `minify` | `boolean` \| `MinifierOptions` | `false` | Minify the output HTML with [html-minifier-terser](https://www.npmjs.com/package/html-minifier-terser). Pass an object to forward html-minifier-terser options. |
46
+
47
+ - Asset
48
+
49
+ ```typescript
50
+ type Asset =
51
+ | string // treated as URL
52
+ | {
53
+ url: string;
54
+ integrity?: string;
55
+ crossorigin?: 'anonymous' | 'use-credentials';
56
+ };
57
+ ```
58
+
59
+ ## How It Works
60
+
61
+ ### 1. Injection
62
+
63
+ Assets are injected into the template in one of two ways:
64
+
65
+ - **Using placeholders** (Recommended)
66
+
67
+ ```html
68
+ <!DOCTYPE html>
69
+ <html>
70
+ <head>
71
+ <title>My App</title>
72
+ <!-- inject:style -->
73
+ </head>
74
+ <body>
75
+ <div id="app"></div>
76
+ <!-- inject:script -->
77
+ </body>
78
+ </html>
79
+ ```
80
+
81
+ The placeholders are configurable via the `styleTagPlaceholder`, `scriptTagPlaceholder` options.
82
+
83
+ - **Using fallbacks**
84
+
85
+ If placeholders are not present, tags are inserted before `</head>` (CSS) or `</body>` (JS) when those tags exist;
86
+
87
+ Otherwise they are prepended (CSS) or appended (JS) to the document.
88
+
89
+ #### Bundled Assets
90
+
91
+ When the bundle is generated, the plugin collects:
92
+
93
+ - **CSS assets** (any emitted asset ending in `.css`)
94
+ - **JS chunks** that are entry points (files ending in `.js`)
95
+
96
+ #### External Assets
97
+
98
+ Use the `external` option to inject assets that are not produced by Rollup (e.g. CDN scripts, third-party stylesheets).
99
+
100
+ External tags are always emitted **before** the bundled tags within the same injection slot.
101
+
102
+ ```js
103
+ html({
104
+ template: 'src/index.html',
105
+ external: {
106
+ style: [
107
+ 'https://cdn.example.com/reset.css',
108
+ {
109
+ url: 'https://cdn.example.com/theme.css',
110
+ integrity: 'sha384-...',
111
+ crossorigin: 'anonymous',
112
+ },
113
+ ],
114
+ script: [
115
+ 'https://cdn.example.com/polyfill.js',
116
+ {
117
+ url: 'https://cdn.example.com/vendor.js',
118
+ integrity: 'sha384-...',
119
+ crossorigin: 'anonymous',
120
+ },
121
+ ],
122
+ },
123
+ });
124
+ ```
125
+
126
+ ### 2. Stripping markup
127
+
128
+ Content (e.g., development-only markup) within stripping markup (including the markup) will be removed from the final output:
129
+
130
+ ```html
131
+ <!-- strip -->
132
+ <p>This will be removed in the final build.</p>
133
+ <!-- /strip -->
134
+ ```
135
+
136
+ The tag name is configurable via the `stripTag` option.
137
+
138
+ ### 3. Minification
139
+
140
+ Enable minification to shrink the final HTML:
141
+
142
+ ```js
143
+ html({
144
+ template: 'src/index.html',
145
+ minify: true,
146
+ });
147
+ ```
148
+
149
+ Or pass custom options:
150
+
151
+ ```js
152
+ html({
153
+ template: 'src/index.html',
154
+ minify: {
155
+ collapseWhitespace: true,
156
+ removeComments: true,
157
+ minifyCSS: true,
158
+ minifyJS: true,
159
+ },
160
+ });
161
+ ```
162
+
163
+ See [`html-minifier-terser` options](https://github.com/terser/html-minifier-terser#options-quick-reference) for the full list.
164
+
165
+ ## License
166
+
167
+ Package `@auioc/rollup-plugin-html` is licensed under the **MIT License**.
168
+ The full license is in the [LICENSE](./LICENSE) file.
package/dist/index.cjs ADDED
@@ -0,0 +1,131 @@
1
+ /*!
2
+ * Package bundle (CJS) of @auioc/rollup-plugin-html
3
+ * https://github.com/auioc/rollup-plugins/tree/main/packages/html
4
+ * Generated at 2026-10-24T11:55:55.128Z
5
+ * Version: v1.1.0 - tag:html@v1.1.0@7188de8e
6
+ * Copyright (C) 2026 AUIOC.ORG
7
+ * Copyright (C) 2022-2026 PCC-Studio
8
+ * Licensed under MIT
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, '__esModule', { value: true });
13
+
14
+ var htmlMinifierTerser = require('html-minifier-terser');
15
+ var fs = require('node:fs');
16
+ var Path = require('node:path');
17
+
18
+ const NAME = 'html';
19
+ const DEFAULT_TERSER_OPTIONS = {
20
+ collapseWhitespace: true,
21
+ removeComments: true,
22
+ };
23
+ function styleTag(asset) {
24
+ if (typeof asset === 'string') {
25
+ return `<link rel="stylesheet" href="${asset}">`;
26
+ }
27
+ const integrity = asset.integrity ? ` integrity="${asset.integrity}"` : '';
28
+ const crossorigin = asset.crossorigin
29
+ ? ` crossorigin="${asset.crossorigin}"`
30
+ : '';
31
+ return `<link rel="stylesheet" href="${asset.url}"${integrity}${crossorigin}>`;
32
+ }
33
+ function scriptTag(asset, module) {
34
+ if (typeof asset === 'string') {
35
+ return `<script ${module ? 'type="module" ' : ''}src="${asset}"></script>`;
36
+ }
37
+ const integrity = asset.integrity ? ` integrity="${asset.integrity}"` : '';
38
+ const crossorigin = asset.crossorigin
39
+ ? ` crossorigin="${asset.crossorigin}"`
40
+ : '';
41
+ return `<script ${module ? 'type="module" ' : ''}src="${asset.url}"${integrity}${crossorigin}></script>`;
42
+ }
43
+ function createHTML(options) {
44
+ const { template: templateFile, output = 'index.html', injectStyle = true, injectScript = true, styleTagPlaceholder = '<!-- inject:style -->', scriptTagPlaceholder = '<!-- inject:script -->', stripTag = 'strip', minify = false, } = options;
45
+ let template = '';
46
+ return {
47
+ name: NAME,
48
+ buildStart() {
49
+ if (!templateFile) {
50
+ throw new Error('Missing `template` option');
51
+ }
52
+ try {
53
+ const path = Path.resolve(process.cwd(), templateFile);
54
+ template = fs.readFileSync(path, 'utf-8');
55
+ }
56
+ catch (error) {
57
+ this.error(String(error));
58
+ }
59
+ },
60
+ async generateBundle(outputOptions, bundle) {
61
+ let html = template;
62
+ // Remove <!-- strip --> ... <!-- /strip -->
63
+ const stripRegex = new RegExp(`<!--\\s*${stripTag}\\s*-->[\\s\\S]*?<!--\\s*/${stripTag}\\s*-->`, 'g');
64
+ html = html.replace(stripRegex, '');
65
+ const jsFiles = [];
66
+ const cssFiles = [];
67
+ for (const [fileName, chunk] of Object.entries(bundle)) {
68
+ if (chunk.type === 'chunk' && fileName.endsWith('.js')) {
69
+ if (chunk.isEntry) {
70
+ jsFiles.push(fileName);
71
+ }
72
+ }
73
+ else if (chunk.type === 'asset') {
74
+ if (fileName.endsWith('.css')) {
75
+ cssFiles.push(fileName);
76
+ }
77
+ }
78
+ }
79
+ const external = options.external ?? { style: [], script: [] };
80
+ if (injectStyle) {
81
+ const externalTags = (external.style ?? []).map(styleTag);
82
+ const bundledTags = cssFiles.map(styleTag);
83
+ const tags = [...externalTags, ...bundledTags].join('\n');
84
+ if (tags) {
85
+ if (html.includes(styleTagPlaceholder)) {
86
+ html = html.replace(styleTagPlaceholder, tags);
87
+ }
88
+ else if (html.includes('</head>')) {
89
+ html = html.replace('</head>', ` ${tags}\n</head>`);
90
+ }
91
+ else {
92
+ html = `${tags}\n${html}`;
93
+ }
94
+ }
95
+ }
96
+ if (injectScript) {
97
+ const _toScriptTag = (asset) => scriptTag(asset, injectScript === 'module');
98
+ const externalTags = (external.script ?? []).map(_toScriptTag);
99
+ const bundledScriptTags = jsFiles.map(_toScriptTag);
100
+ const tags = [...externalTags, ...bundledScriptTags].join('\n');
101
+ if (tags) {
102
+ if (html.includes(scriptTagPlaceholder)) {
103
+ html = html.replace(scriptTagPlaceholder, tags);
104
+ }
105
+ else if (html.includes('</body>')) {
106
+ html = html.replace('</body>', ` ${tags}\n</body>`);
107
+ }
108
+ else {
109
+ html += `\n${tags}`;
110
+ }
111
+ }
112
+ }
113
+ if (minify) {
114
+ const minifyOptions = typeof minify === 'object'
115
+ ? minify
116
+ : DEFAULT_TERSER_OPTIONS;
117
+ html = await htmlMinifierTerser.minify(html, minifyOptions);
118
+ }
119
+ const asset = {
120
+ type: 'asset',
121
+ fileName: output,
122
+ name: output,
123
+ source: html,
124
+ needsCodeReference: false,
125
+ };
126
+ this.emitFile(asset);
127
+ },
128
+ };
129
+ }
130
+
131
+ exports.default = createHTML;
@@ -0,0 +1,74 @@
1
+ /*!
2
+ * Type definitions of @auioc/rollup-plugin-html
3
+ * https://github.com/auioc/rollup-plugins/tree/main/packages/html
4
+ * Generated at 2026-10-24T11:55:55.128Z
5
+ * Version: v1.1.0 - tag:html@v1.1.0@7188de8e
6
+ * Copyright (C) 2026 AUIOC.ORG
7
+ * Copyright (C) 2022-2026 PCC-Studio
8
+ * Licensed under MIT
9
+ */
10
+ import { Options as Options$1 } from 'html-minifier-terser';
11
+ import { Plugin } from 'rollup';
12
+
13
+ type Asset = string | {
14
+ url: string;
15
+ integrity?: string;
16
+ crossorigin?: 'anonymous' | 'use-credentials';
17
+ };
18
+ interface Options {
19
+ /**
20
+ * Path of template `.html` file
21
+ */
22
+ template: string;
23
+ /**
24
+ * Output file name
25
+ * @default 'index.html'
26
+ */
27
+ output?: string;
28
+ /**
29
+ * Whether to inject bundled CSS files.
30
+ * @default true
31
+ */
32
+ injectStyle?: boolean;
33
+ /**
34
+ * Whether to inject bundled JS files.
35
+ * Use `'module'` to add `type="module"`.
36
+ * @default true
37
+ */
38
+ injectScript?: boolean | 'module';
39
+ /**
40
+ * External assets to inject.
41
+ * @default {}
42
+ */
43
+ external?: {
44
+ style?: Asset[];
45
+ script?: Asset[];
46
+ };
47
+ /**
48
+ * Placeholder comment replaced by CSS tags.
49
+ * @default '<!-- inject:style -->'
50
+ */
51
+ styleTagPlaceholder?: string;
52
+ /**
53
+ * Placeholder comment replaced by script tags.
54
+ * @default '<!-- inject:script -->'
55
+ */
56
+ scriptTagPlaceholder?: string;
57
+ /**
58
+ * Tag name used for strip comment blocks.
59
+ *
60
+ * Content within `<!-- strip --><!-- /strip -->` (including the markup) will be removed from the final output.
61
+ * @default 'strip'
62
+ */
63
+ stripTag?: string;
64
+ /**
65
+ * Minify the output HTML.
66
+ * @see {@link MinifierOptions}
67
+ * @default false
68
+ */
69
+ minify?: boolean | Options$1;
70
+ }
71
+ declare function createHTML(options: Options): Plugin;
72
+
73
+ export { createHTML as default };
74
+ export type { Asset, Options };
package/dist/index.mjs ADDED
@@ -0,0 +1,127 @@
1
+ /*!
2
+ * Package bundle (ESM) of @auioc/rollup-plugin-html
3
+ * https://github.com/auioc/rollup-plugins/tree/main/packages/html
4
+ * Generated at 2026-10-24T11:55:55.128Z
5
+ * Version: v1.1.0 - tag:html@v1.1.0@7188de8e
6
+ * Copyright (C) 2026 AUIOC.ORG
7
+ * Copyright (C) 2022-2026 PCC-Studio
8
+ * Licensed under MIT
9
+ */
10
+ import { minify } from 'html-minifier-terser';
11
+ import fs from 'node:fs';
12
+ import Path from 'node:path';
13
+
14
+ const NAME = 'html';
15
+ const DEFAULT_TERSER_OPTIONS = {
16
+ collapseWhitespace: true,
17
+ removeComments: true,
18
+ };
19
+ function styleTag(asset) {
20
+ if (typeof asset === 'string') {
21
+ return `<link rel="stylesheet" href="${asset}">`;
22
+ }
23
+ const integrity = asset.integrity ? ` integrity="${asset.integrity}"` : '';
24
+ const crossorigin = asset.crossorigin
25
+ ? ` crossorigin="${asset.crossorigin}"`
26
+ : '';
27
+ return `<link rel="stylesheet" href="${asset.url}"${integrity}${crossorigin}>`;
28
+ }
29
+ function scriptTag(asset, module) {
30
+ if (typeof asset === 'string') {
31
+ return `<script ${module ? 'type="module" ' : ''}src="${asset}"></script>`;
32
+ }
33
+ const integrity = asset.integrity ? ` integrity="${asset.integrity}"` : '';
34
+ const crossorigin = asset.crossorigin
35
+ ? ` crossorigin="${asset.crossorigin}"`
36
+ : '';
37
+ return `<script ${module ? 'type="module" ' : ''}src="${asset.url}"${integrity}${crossorigin}></script>`;
38
+ }
39
+ function createHTML(options) {
40
+ const { template: templateFile, output = 'index.html', injectStyle = true, injectScript = true, styleTagPlaceholder = '<!-- inject:style -->', scriptTagPlaceholder = '<!-- inject:script -->', stripTag = 'strip', minify: minify$1 = false, } = options;
41
+ let template = '';
42
+ return {
43
+ name: NAME,
44
+ buildStart() {
45
+ if (!templateFile) {
46
+ throw new Error('Missing `template` option');
47
+ }
48
+ try {
49
+ const path = Path.resolve(process.cwd(), templateFile);
50
+ template = fs.readFileSync(path, 'utf-8');
51
+ }
52
+ catch (error) {
53
+ this.error(String(error));
54
+ }
55
+ },
56
+ async generateBundle(outputOptions, bundle) {
57
+ let html = template;
58
+ // Remove <!-- strip --> ... <!-- /strip -->
59
+ const stripRegex = new RegExp(`<!--\\s*${stripTag}\\s*-->[\\s\\S]*?<!--\\s*/${stripTag}\\s*-->`, 'g');
60
+ html = html.replace(stripRegex, '');
61
+ const jsFiles = [];
62
+ const cssFiles = [];
63
+ for (const [fileName, chunk] of Object.entries(bundle)) {
64
+ if (chunk.type === 'chunk' && fileName.endsWith('.js')) {
65
+ if (chunk.isEntry) {
66
+ jsFiles.push(fileName);
67
+ }
68
+ }
69
+ else if (chunk.type === 'asset') {
70
+ if (fileName.endsWith('.css')) {
71
+ cssFiles.push(fileName);
72
+ }
73
+ }
74
+ }
75
+ const external = options.external ?? { style: [], script: [] };
76
+ if (injectStyle) {
77
+ const externalTags = (external.style ?? []).map(styleTag);
78
+ const bundledTags = cssFiles.map(styleTag);
79
+ const tags = [...externalTags, ...bundledTags].join('\n');
80
+ if (tags) {
81
+ if (html.includes(styleTagPlaceholder)) {
82
+ html = html.replace(styleTagPlaceholder, tags);
83
+ }
84
+ else if (html.includes('</head>')) {
85
+ html = html.replace('</head>', ` ${tags}\n</head>`);
86
+ }
87
+ else {
88
+ html = `${tags}\n${html}`;
89
+ }
90
+ }
91
+ }
92
+ if (injectScript) {
93
+ const _toScriptTag = (asset) => scriptTag(asset, injectScript === 'module');
94
+ const externalTags = (external.script ?? []).map(_toScriptTag);
95
+ const bundledScriptTags = jsFiles.map(_toScriptTag);
96
+ const tags = [...externalTags, ...bundledScriptTags].join('\n');
97
+ if (tags) {
98
+ if (html.includes(scriptTagPlaceholder)) {
99
+ html = html.replace(scriptTagPlaceholder, tags);
100
+ }
101
+ else if (html.includes('</body>')) {
102
+ html = html.replace('</body>', ` ${tags}\n</body>`);
103
+ }
104
+ else {
105
+ html += `\n${tags}`;
106
+ }
107
+ }
108
+ }
109
+ if (minify$1) {
110
+ const minifyOptions = typeof minify$1 === 'object'
111
+ ? minify$1
112
+ : DEFAULT_TERSER_OPTIONS;
113
+ html = await minify(html, minifyOptions);
114
+ }
115
+ const asset = {
116
+ type: 'asset',
117
+ fileName: output,
118
+ name: output,
119
+ source: html,
120
+ needsCodeReference: false,
121
+ };
122
+ this.emitFile(asset);
123
+ },
124
+ };
125
+ }
126
+
127
+ export { createHTML as default };
package/package.json CHANGED
@@ -1,10 +1,47 @@
1
1
  {
2
2
  "name": "@auioc/rollup-plugin-html",
3
- "version": "0.0.0",
4
- "description": "OIDC trusted publishing setup package for @auioc/rollup-plugin-html",
3
+ "version": "1.1.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "Rollup plugin - create html file from template to serve bundled js/css",
5
8
  "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
9
- ]
10
- }
9
+ "rollup",
10
+ "plugin",
11
+ "rollup-plugin",
12
+ "html",
13
+ "template"
14
+ ],
15
+ "license": "MIT",
16
+ "homepage": "https://github.com/auioc/rollup-plugins/tree/main/packages/html",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/auioc/rollup-plugins.git",
20
+ "directory": "packages/html"
21
+ },
22
+ "author": {
23
+ "name": "AUIOC",
24
+ "url": "https://www.auioc.org"
25
+ },
26
+ "type": "module",
27
+ "main": "./dist/index.cjs",
28
+ "module": "./dist/index.mjs",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.mjs",
33
+ "default": "./dist/index.cjs"
34
+ },
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "dependencies": {
39
+ "html-minifier-terser": "^7.2.0"
40
+ },
41
+ "devDependencies": {
42
+ "@types/html-minifier-terser": "^7.0.2"
43
+ },
44
+ "scripts": {
45
+ "build": "rollup -c"
46
+ }
47
+ }