@auioc/rollup-plugin-html 1.2.0 → 1.3.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/README.md CHANGED
@@ -32,18 +32,18 @@ export default {
32
32
 
33
33
  ## Options
34
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. See [External Assets](#external-assets). |
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
- | `cacheBusting` | `CacheBusting` (`boolean` \| `string` \| `Function`) | `false` | Append a query string to bundled asset URLs. See [Cache busting](#4-cache-busting). |
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` \| `((id: string) => boolean)` | `true` | Whether to inject styles.<br/>Pass a function to decide per-asset whether to inject it. The function receives the asset URL (for external assets) or the bundled file name. |
40
+ | `injectScript` | `boolean` \| `'module'` \| `((id: string) => boolean \| 'module')` | `true` | Whether to inject scripts.<br/>Use `'module'` to add `type="module"`.<br/>Pass a function to decide per-asset whether (and how) to inject it. The function receives the asset URL (for external assets) or the bundled file name. |
41
+ | `external` | `{ style?: Asset[]; script?: Asset[] }` | `{ }` | External assets to inject. Their tags are placed before the bundled ones. See [External Assets](#external-assets). |
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
+ | `cacheBusting` | `CacheBusting` (`boolean` \| `string` \| `Function`) | `false` | Append a query string to bundled asset URLs. See [Cache busting](#4-cache-busting). |
47
47
 
48
48
  - Asset
49
49
 
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  /*!
2
2
  * Package bundle (CJS) of @auioc/rollup-plugin-html
3
3
  * https://github.com/auioc/rollup-plugins/tree/main/packages/html
4
- * Generated at 2026-11-01T16:54:06.132Z
5
- * Version: v1.2.0 - tag:html@v1.2.0@20a23efd
4
+ * Generated at 2026-11-09T16:23:53.666Z
5
+ * Version: v1.3.0 - tag:html@v1.3.0@9873e315
6
6
  * Copyright (C) 2026 AUIOC.ORG
7
7
  * Copyright (C) 2022-2026 PCC-Studio
8
8
  * Licensed under MIT
@@ -102,8 +102,13 @@ function createHTML(options) {
102
102
  }
103
103
  const external = options.external ?? { style: [], script: [] };
104
104
  if (injectStyle) {
105
- const externalTags = (external.style ?? []).map(styleTag);
106
- const bundledTags = cssFiles.map(styleTag);
105
+ const predicate = typeof injectStyle === 'function'
106
+ ? injectStyle
107
+ : () => true;
108
+ const externalTags = (external.style ?? [])
109
+ .filter((x) => predicate(typeof x === 'string' ? x : x.url))
110
+ .map(styleTag);
111
+ const bundledTags = cssFiles.filter(predicate).map(styleTag);
107
112
  const tags = [...externalTags, ...bundledTags].join('\n');
108
113
  if (tags) {
109
114
  if (html.includes(styleTagPlaceholder)) {
@@ -118,10 +123,21 @@ function createHTML(options) {
118
123
  }
119
124
  }
120
125
  if (injectScript) {
121
- const _toScriptTag = (asset) => scriptTag(asset, injectScript === 'module');
126
+ const predicate = typeof injectScript === 'function'
127
+ ? injectScript
128
+ : () => injectScript;
129
+ const _toScriptTag = (asset) => {
130
+ const type = predicate(typeof asset === 'string' ? asset : asset.url);
131
+ if (type) {
132
+ return scriptTag(asset, type === 'module');
133
+ }
134
+ return undefined;
135
+ };
122
136
  const externalTags = (external.script ?? []).map(_toScriptTag);
123
137
  const bundledScriptTags = jsFiles.map(_toScriptTag);
124
- const tags = [...externalTags, ...bundledScriptTags].join('\n');
138
+ const tags = [...externalTags, ...bundledScriptTags]
139
+ .filter((x) => !!x)
140
+ .join('\n');
125
141
  if (tags) {
126
142
  if (html.includes(scriptTagPlaceholder)) {
127
143
  html = html.replace(scriptTagPlaceholder, tags);
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /*!
2
2
  * Type definitions of @auioc/rollup-plugin-html
3
3
  * https://github.com/auioc/rollup-plugins/tree/main/packages/html
4
- * Generated at 2026-11-01T16:54:06.132Z
5
- * Version: v1.2.0 - tag:html@v1.2.0@20a23efd
4
+ * Generated at 2026-11-09T16:23:53.666Z
5
+ * Version: v1.3.0 - tag:html@v1.3.0@9873e315
6
6
  * Copyright (C) 2026 AUIOC.ORG
7
7
  * Copyright (C) 2022-2026 PCC-Studio
8
8
  * Licensed under MIT
@@ -28,19 +28,26 @@ interface Options {
28
28
  output?: string;
29
29
  /**
30
30
  * Whether to inject bundled CSS files.
31
+ *
32
+ * Pass a function to decide per-asset whether to inject it.
33
+ * The function receives the asset URL (for external assets) or the
34
+ * bundled file name.
31
35
  * @default true
32
36
  */
33
- injectStyle?: boolean;
37
+ injectStyle?: boolean | ((id: string) => boolean);
34
38
  /**
35
39
  * Whether to inject bundled JS files.
40
+ *
36
41
  * Use `'module'` to add `type="module"`.
42
+ *
43
+ * Pass a function to decide per-asset whether (and how) to inject it.
44
+ * The function receives the asset URL (for external assets) or the
45
+ * bundled file name, return `false` to skip injection,
46
+ * `'module'` to inject with `type="module"`, or `true` to inject a
47
+ * normal script tag.
37
48
  * @default true
38
49
  */
39
- injectScript?: boolean | 'module';
40
- /**
41
- * External assets to inject.
42
- * @default {}
43
- */
50
+ injectScript?: boolean | 'module' | ((id: string) => boolean | 'module');
44
51
  external?: {
45
52
  style?: Asset[];
46
53
  script?: Asset[];
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  /*!
2
2
  * Package bundle (ESM) of @auioc/rollup-plugin-html
3
3
  * https://github.com/auioc/rollup-plugins/tree/main/packages/html
4
- * Generated at 2026-11-01T16:54:06.132Z
5
- * Version: v1.2.0 - tag:html@v1.2.0@20a23efd
4
+ * Generated at 2026-11-09T16:23:53.666Z
5
+ * Version: v1.3.0 - tag:html@v1.3.0@9873e315
6
6
  * Copyright (C) 2026 AUIOC.ORG
7
7
  * Copyright (C) 2022-2026 PCC-Studio
8
8
  * Licensed under MIT
@@ -98,8 +98,13 @@ function createHTML(options) {
98
98
  }
99
99
  const external = options.external ?? { style: [], script: [] };
100
100
  if (injectStyle) {
101
- const externalTags = (external.style ?? []).map(styleTag);
102
- const bundledTags = cssFiles.map(styleTag);
101
+ const predicate = typeof injectStyle === 'function'
102
+ ? injectStyle
103
+ : () => true;
104
+ const externalTags = (external.style ?? [])
105
+ .filter((x) => predicate(typeof x === 'string' ? x : x.url))
106
+ .map(styleTag);
107
+ const bundledTags = cssFiles.filter(predicate).map(styleTag);
103
108
  const tags = [...externalTags, ...bundledTags].join('\n');
104
109
  if (tags) {
105
110
  if (html.includes(styleTagPlaceholder)) {
@@ -114,10 +119,21 @@ function createHTML(options) {
114
119
  }
115
120
  }
116
121
  if (injectScript) {
117
- const _toScriptTag = (asset) => scriptTag(asset, injectScript === 'module');
122
+ const predicate = typeof injectScript === 'function'
123
+ ? injectScript
124
+ : () => injectScript;
125
+ const _toScriptTag = (asset) => {
126
+ const type = predicate(typeof asset === 'string' ? asset : asset.url);
127
+ if (type) {
128
+ return scriptTag(asset, type === 'module');
129
+ }
130
+ return undefined;
131
+ };
118
132
  const externalTags = (external.script ?? []).map(_toScriptTag);
119
133
  const bundledScriptTags = jsFiles.map(_toScriptTag);
120
- const tags = [...externalTags, ...bundledScriptTags].join('\n');
134
+ const tags = [...externalTags, ...bundledScriptTags]
135
+ .filter((x) => !!x)
136
+ .join('\n');
121
137
  if (tags) {
122
138
  if (html.includes(scriptTagPlaceholder)) {
123
139
  html = html.replace(scriptTagPlaceholder, tags);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auioc/rollup-plugin-html",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "author": {
23
23
  "name": "AUIOC",
24
- "url": "https://www.auioc.org"
24
+ "url": "https://auioc.org"
25
25
  },
26
26
  "type": "module",
27
27
  "main": "./dist/index.cjs",