@auioc/rollup-plugin-html 0.0.0 → 1.0.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,121 @@
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 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: { dir: 'dist', format: 'es' },
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` | | Path to the template `.html` file, resolved relative to `process.cwd()`. **required**. |
38
+ | `output` | `string` | `'index.html'` | Output file name of the emitted HTML file. |
39
+ | `injectStyle` | `boolean` | `true` | Whether to inject bundled CSS files. |
40
+ | `injectScript` | `boolean` \| `'module'` | `true` | Whether to inject bundled JS files. Use `'module'` to add `type="module"`. |
41
+ | `styleTagPlaceholder` | `string` | `'<!-- inject:style -->'` | Placeholder comment replaced by CSS tags. |
42
+ | `scriptTagPlaceholder` | `string` | `'<!-- inject:script -->'` | Placeholder comment replaced by script tags. |
43
+ | `stripTag` | `string` | `'strip'` | Tag name used for strip comment blocks. |
44
+ | `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. |
45
+
46
+ ## How It Works
47
+
48
+ ### 1. Injection
49
+
50
+ When the bundle is generated, the plugin collects:
51
+
52
+ - **CSS assets** (any emitted asset ending in `.css`)
53
+ - **JS chunks** that are entry points or dynamic entry points (files ending in `.js`)
54
+
55
+ These are injected into the template in one of two ways:
56
+
57
+ #### Using placeholders (Recommended)
58
+
59
+ ```html
60
+ <!DOCTYPE html>
61
+ <html>
62
+ <head>
63
+ <title>My App</title>
64
+ <!-- inject:style -->
65
+ </head>
66
+ <body>
67
+ <div id="app"></div>
68
+ <!-- inject:script -->
69
+ </body>
70
+ </html>
71
+ ```
72
+
73
+ The placeholders are configurable via the `styleTagPlaceholder`, `scriptTagPlaceholder` options.
74
+
75
+ #### Using fallbacks
76
+
77
+ If placeholders are not present, tags are inserted before `</head>` (CSS) or `</body>` (JS) when those tags exist; otherwise they are prepended (CSS) or appended (JS) to the document.
78
+
79
+ ### 2. Stripping markup
80
+
81
+ Content (e.g., development-only markup) within stripping markup (including the markup) will be removed from the final output:
82
+
83
+ ```html
84
+ <!-- strip -->
85
+ <p>This will be removed in the final build.</p>
86
+ <!-- /strip -->
87
+ ```
88
+
89
+ The tag name is configurable via the `stripTag` option.
90
+
91
+ ### 4. Minification
92
+
93
+ Enable minification to shrink the final HTML:
94
+
95
+ ```js
96
+ html({
97
+ template: 'src/index.html',
98
+ minify: true,
99
+ });
100
+ ```
101
+
102
+ Or pass custom options:
103
+
104
+ ```js
105
+ html({
106
+ template: 'src/index.html',
107
+ minify: {
108
+ collapseWhitespace: true,
109
+ removeComments: true,
110
+ minifyCSS: true,
111
+ minifyJS: true,
112
+ },
113
+ });
114
+ ```
115
+
116
+ See [`html-minifier-terser` options](https://github.com/terser/html-minifier-terser#options-quick-reference) for the full list.
117
+
118
+ ## License
119
+
120
+ Package `@auioc/rollup-plugin-html` is licensed under the **MIT License**.
121
+ The full license is in the [LICENSE](./LICENSE) file.
package/dist/index.cjs ADDED
@@ -0,0 +1,99 @@
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-03T16:27:04.048Z
5
+ * Version: v1.0.0 - tag:html@v1.0.0@20c4ec2b
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
+ function createHTML(options) {
20
+ const { template: templateFile, output = 'index.html', injectStyle = true, injectScript = true, styleTagPlaceholder = '<!-- inject:style -->', scriptTagPlaceholder = '<!-- inject:script -->', stripTag = 'strip', minify = false, } = options;
21
+ let template = '';
22
+ return {
23
+ name: NAME,
24
+ buildStart() {
25
+ if (!templateFile) {
26
+ throw new Error('Missing `template` option');
27
+ }
28
+ try {
29
+ const path = Path.resolve(process.cwd(), templateFile);
30
+ template = fs.readFileSync(path, 'utf-8');
31
+ }
32
+ catch (error) {
33
+ this.error(String(error));
34
+ }
35
+ },
36
+ async generateBundle(outputOptions, bundle) {
37
+ let html = template;
38
+ // Remove <!-- strip --> ... <!-- /strip -->
39
+ const stripRegex = new RegExp(`<!--\\s*${stripTag}\\s*-->[\\s\\S]*?<!--\\s*/${stripTag}\\s*-->`, 'g');
40
+ html = html.replace(stripRegex, '');
41
+ const jsFiles = [];
42
+ const cssFiles = [];
43
+ for (const [fileName, chunk] of Object.entries(bundle)) {
44
+ if (chunk.type === 'chunk' && fileName.endsWith('.js')) {
45
+ if (chunk.isEntry || chunk.isDynamicEntry) {
46
+ jsFiles.push(fileName);
47
+ }
48
+ }
49
+ else if (chunk.type === 'asset') {
50
+ if (fileName.endsWith('.css')) {
51
+ cssFiles.push(fileName);
52
+ }
53
+ }
54
+ }
55
+ if (injectStyle && cssFiles.length > 0) {
56
+ const tags = cssFiles
57
+ .map((file) => `<link rel="stylesheet" href="${file}">`)
58
+ .join('\n');
59
+ if (html.includes(styleTagPlaceholder)) {
60
+ html = html.replace(styleTagPlaceholder, tags);
61
+ }
62
+ else if (html.includes('</head>')) {
63
+ html = html.replace('</head>', ` ${tags}\n</head>`);
64
+ }
65
+ else {
66
+ html = `${tags}\n${html}`;
67
+ }
68
+ }
69
+ if (injectScript && jsFiles.length > 0) {
70
+ const tags = jsFiles
71
+ .map((file) => `<script ${injectScript === 'module' ? 'type="module" ' : ''}src="${file}"></script>`)
72
+ .join('\n');
73
+ if (html.includes(scriptTagPlaceholder)) {
74
+ html = html.replace(scriptTagPlaceholder, tags);
75
+ }
76
+ else if (html.includes('</body>')) {
77
+ html = html.replace('</body>', ` ${tags}\n</body>`);
78
+ }
79
+ else {
80
+ html += `\n${tags}`;
81
+ }
82
+ }
83
+ if (minify) {
84
+ const minifyOptions = typeof minify === 'object' ? minify : {};
85
+ html = await htmlMinifierTerser.minify(html, minifyOptions);
86
+ }
87
+ const asset = {
88
+ type: 'asset',
89
+ fileName: output,
90
+ name: output,
91
+ source: html,
92
+ needsCodeReference: false,
93
+ };
94
+ this.emitFile(asset);
95
+ },
96
+ };
97
+ }
98
+
99
+ exports.default = createHTML;
@@ -0,0 +1,61 @@
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-03T16:27:04.048Z
5
+ * Version: v1.0.0 - tag:html@v1.0.0@20c4ec2b
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
+ interface Options {
14
+ /**
15
+ * Path of template `.html` file
16
+ */
17
+ template: string;
18
+ /**
19
+ * Output file name
20
+ * @default 'index.html'
21
+ */
22
+ output?: string;
23
+ /**
24
+ * Whether to inject bundled CSS files.
25
+ * @default true
26
+ */
27
+ injectStyle?: boolean;
28
+ /**
29
+ * Whether to inject bundled JS files.
30
+ * Use `'module'` to add `type="module"`.
31
+ * @default true
32
+ */
33
+ injectScript?: boolean | 'module';
34
+ /**
35
+ * Placeholder comment replaced by CSS tags.
36
+ * @default '<!-- inject:style -->'
37
+ */
38
+ styleTagPlaceholder?: string;
39
+ /**
40
+ * Placeholder comment replaced by script tags.
41
+ * @default '<!-- inject:script -->'
42
+ */
43
+ scriptTagPlaceholder?: string;
44
+ /**
45
+ * Tag name used for strip comment blocks.
46
+ *
47
+ * Content within `<!-- strip --><!-- /strip -->` (including the markup) will be removed from the final output.
48
+ * @default 'strip'
49
+ */
50
+ stripTag?: string;
51
+ /**
52
+ * Minify the output HTML.
53
+ * @see {@link MinifierOptions}
54
+ * @default false
55
+ */
56
+ minify?: boolean | Options$1;
57
+ }
58
+ declare function createHTML(options: Options): Plugin;
59
+
60
+ export { createHTML as default };
61
+ export type { Options };
package/dist/index.mjs ADDED
@@ -0,0 +1,95 @@
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-03T16:27:04.048Z
5
+ * Version: v1.0.0 - tag:html@v1.0.0@20c4ec2b
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
+ function createHTML(options) {
16
+ const { template: templateFile, output = 'index.html', injectStyle = true, injectScript = true, styleTagPlaceholder = '<!-- inject:style -->', scriptTagPlaceholder = '<!-- inject:script -->', stripTag = 'strip', minify: minify$1 = false, } = options;
17
+ let template = '';
18
+ return {
19
+ name: NAME,
20
+ buildStart() {
21
+ if (!templateFile) {
22
+ throw new Error('Missing `template` option');
23
+ }
24
+ try {
25
+ const path = Path.resolve(process.cwd(), templateFile);
26
+ template = fs.readFileSync(path, 'utf-8');
27
+ }
28
+ catch (error) {
29
+ this.error(String(error));
30
+ }
31
+ },
32
+ async generateBundle(outputOptions, bundle) {
33
+ let html = template;
34
+ // Remove <!-- strip --> ... <!-- /strip -->
35
+ const stripRegex = new RegExp(`<!--\\s*${stripTag}\\s*-->[\\s\\S]*?<!--\\s*/${stripTag}\\s*-->`, 'g');
36
+ html = html.replace(stripRegex, '');
37
+ const jsFiles = [];
38
+ const cssFiles = [];
39
+ for (const [fileName, chunk] of Object.entries(bundle)) {
40
+ if (chunk.type === 'chunk' && fileName.endsWith('.js')) {
41
+ if (chunk.isEntry || chunk.isDynamicEntry) {
42
+ jsFiles.push(fileName);
43
+ }
44
+ }
45
+ else if (chunk.type === 'asset') {
46
+ if (fileName.endsWith('.css')) {
47
+ cssFiles.push(fileName);
48
+ }
49
+ }
50
+ }
51
+ if (injectStyle && cssFiles.length > 0) {
52
+ const tags = cssFiles
53
+ .map((file) => `<link rel="stylesheet" href="${file}">`)
54
+ .join('\n');
55
+ if (html.includes(styleTagPlaceholder)) {
56
+ html = html.replace(styleTagPlaceholder, tags);
57
+ }
58
+ else if (html.includes('</head>')) {
59
+ html = html.replace('</head>', ` ${tags}\n</head>`);
60
+ }
61
+ else {
62
+ html = `${tags}\n${html}`;
63
+ }
64
+ }
65
+ if (injectScript && jsFiles.length > 0) {
66
+ const tags = jsFiles
67
+ .map((file) => `<script ${injectScript === 'module' ? 'type="module" ' : ''}src="${file}"></script>`)
68
+ .join('\n');
69
+ if (html.includes(scriptTagPlaceholder)) {
70
+ html = html.replace(scriptTagPlaceholder, tags);
71
+ }
72
+ else if (html.includes('</body>')) {
73
+ html = html.replace('</body>', ` ${tags}\n</body>`);
74
+ }
75
+ else {
76
+ html += `\n${tags}`;
77
+ }
78
+ }
79
+ if (minify$1) {
80
+ const minifyOptions = typeof minify$1 === 'object' ? minify$1 : {};
81
+ html = await minify(html, minifyOptions);
82
+ }
83
+ const asset = {
84
+ type: 'asset',
85
+ fileName: output,
86
+ name: output,
87
+ source: html,
88
+ needsCodeReference: false,
89
+ };
90
+ this.emitFile(asset);
91
+ },
92
+ };
93
+ }
94
+
95
+ 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.0.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
+ }