@web/rollup-plugin-html 2.4.0 → 3.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/dist/RollupPluginHTMLOptions.d.ts +2 -4
- package/dist/RollupPluginHTMLOptions.d.ts.map +1 -1
- package/dist/assets/utils.d.ts +1 -1
- package/dist/assets/utils.d.ts.map +1 -1
- package/dist/assets/utils.js +29 -11
- package/dist/assets/utils.js.map +1 -1
- package/dist/input/extract/extractAssets.d.ts +1 -0
- package/dist/input/extract/extractAssets.d.ts.map +1 -1
- package/dist/input/extract/extractAssets.js +2 -2
- package/dist/input/extract/extractAssets.js.map +1 -1
- package/dist/input/extract/extractModulesAndAssets.d.ts +1 -1
- package/dist/input/extract/extractModulesAndAssets.d.ts.map +1 -1
- package/dist/input/extract/extractModulesAndAssets.js +1 -0
- package/dist/input/extract/extractModulesAndAssets.js.map +1 -1
- package/dist/input/getInputData.d.ts +1 -1
- package/dist/input/getInputData.d.ts.map +1 -1
- package/dist/input/getInputData.js +1 -1
- package/dist/input/getInputData.js.map +1 -1
- package/dist/output/createHTMLOutput.d.ts +2 -4
- package/dist/output/createHTMLOutput.d.ts.map +1 -1
- package/dist/output/createHTMLOutput.js +33 -4
- package/dist/output/createHTMLOutput.js.map +1 -1
- package/dist/output/emitAssets.d.ts.map +1 -1
- package/dist/output/emitAssets.js +43 -10
- package/dist/output/emitAssets.js.map +1 -1
- package/dist/output/getOutputHTML.d.ts +1 -2
- package/dist/output/getOutputHTML.d.ts.map +1 -1
- package/dist/output/getOutputHTML.js +7 -16
- package/dist/output/getOutputHTML.js.map +1 -1
- package/dist/output/injectedUpdatedAssetPaths.d.ts +1 -0
- package/dist/output/injectedUpdatedAssetPaths.d.ts.map +1 -1
- package/dist/output/injectedUpdatedAssetPaths.js +4 -2
- package/dist/output/injectedUpdatedAssetPaths.js.map +1 -1
- package/dist/rollupPluginHTML.d.ts +1 -1
- package/dist/rollupPluginHTML.d.ts.map +1 -1
- package/dist/rollupPluginHTML.js +6 -16
- package/dist/rollupPluginHTML.js.map +1 -1
- package/package.json +4 -1
- package/src/RollupPluginHTMLOptions.ts +2 -4
- package/src/assets/utils.ts +27 -8
- package/src/input/extract/extractAssets.ts +3 -2
- package/src/input/extract/extractModulesAndAssets.ts +2 -1
- package/src/input/getInputData.ts +10 -3
- package/src/output/createHTMLOutput.ts +13 -9
- package/src/output/emitAssets.ts +40 -12
- package/src/output/getOutputHTML.ts +8 -21
- package/src/output/injectedUpdatedAssetPaths.ts +5 -1
- package/src/rollupPluginHTML.ts +7 -22
|
@@ -20,7 +20,7 @@ function getSrcSetUrlWidthPairs(srcset) {
|
|
|
20
20
|
return urls;
|
|
21
21
|
}
|
|
22
22
|
function injectedUpdatedAssetPaths(args) {
|
|
23
|
-
const { document, input, outputDir, rootDir, emittedAssets, externalAssets, publicPath = './', absolutePathPrefix, } = args;
|
|
23
|
+
const { document, input, outputDir, rootDir, emittedAssets, extractAssets = true, externalAssets, publicPath = './', absolutePathPrefix, } = args;
|
|
24
24
|
const assetNodes = (0, utils_js_1.findAssets)(document);
|
|
25
25
|
const isExternal = (0, utils_js_1.createAssetPicomatchMatcher)(externalAssets);
|
|
26
26
|
for (const node of assetNodes) {
|
|
@@ -31,7 +31,9 @@ function injectedUpdatedAssetPaths(args) {
|
|
|
31
31
|
const htmlFilePath = input.filePath ? input.filePath : path_1.default.join(rootDir, input.name);
|
|
32
32
|
const htmlDir = path_1.default.dirname(htmlFilePath);
|
|
33
33
|
const filePath = (0, utils_js_1.resolveAssetFilePath)(sourcePath, htmlDir, rootDir, absolutePathPrefix);
|
|
34
|
-
const assetPaths = (0, utils_js_1.isHashedAsset)(node)
|
|
34
|
+
const assetPaths = (0, utils_js_1.isHashedAsset)(node, extractAssets)
|
|
35
|
+
? emittedAssets.hashed
|
|
36
|
+
: emittedAssets.static;
|
|
35
37
|
const relativeOutputPath = assetPaths.get(filePath);
|
|
36
38
|
if (!relativeOutputPath) {
|
|
37
39
|
throw (0, utils_js_2.createError)(`Something went wrong while bundling HTML file ${input.name}. Could not find ${filePath} in emitted rollup assets.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectedUpdatedAssetPaths.js","sourceRoot":"","sources":["../../src/output/injectedUpdatedAssetPaths.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA+D;AAE/D,gDAAwB;AAExB,iDAO4B;AAE5B,0CAA0C;AAE1C,yCAA2C;
|
|
1
|
+
{"version":3,"file":"injectedUpdatedAssetPaths.js","sourceRoot":"","sources":["../../src/output/injectedUpdatedAssetPaths.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA+D;AAE/D,gDAAwB;AAExB,iDAO4B;AAE5B,0CAA0C;AAE1C,yCAA2C;AAc3C,SAAS,sBAAsB,CAAC,MAAc;IAC5C,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAC;KACX;IACD,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACxE,MAAM,IAAI,GAAG,WAAW;SACrB,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;SACtB,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC5D,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAgB,yBAAyB,CAAC,IAAiC;IACzE,MAAM,EACJ,QAAQ,EACR,KAAK,EACL,SAAS,EACT,OAAO,EACP,aAAa,EACb,aAAa,GAAG,IAAI,EACpB,cAAc,EACd,UAAU,GAAG,IAAI,EACjB,kBAAkB,GACnB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AAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;YACpE,MAAM,sBAAsB,GAAG,cAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;YAEhF,MAAM,WAAW,GAAG,cAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,IAAA,wBAAa,EAAC,sBAAsB,CAAC,CAAC,CAAC;YACvF,MAAM,GAAG,GAAG,IAAA,6BAAkB,EAAC,IAAI,CAAC,CAAC;YAErC,IAAI,iBAAiB,GAAG,WAAW,CAAC;YACpC,IAAI,GAAG,KAAK,QAAQ,EAAE;gBACpB,MAAM,MAAM,GAAG,IAAA,2BAAY,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC;gBACvC,IAAI,MAAM,EAAE;oBACV,MAAM,aAAa,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;oBACrD,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE;wBACxC,IAAI,YAAY,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE;4BAClC,YAAY,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;yBAC/B;qBACF;oBACD,iBAAiB,GAAG,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;iBAC1F;aACF;YAED,IAAA,2BAAY,EAAC,IAAI,EAAE,GAAG,EAAE,iBAAiB,CAAC,CAAC;SAC5C;KACF;AACH,CAAC;AA1DD,8DA0DC"}
|
|
@@ -4,7 +4,7 @@ import { RollupPluginHTMLOptions, TransformHtmlFunction } from './RollupPluginHT
|
|
|
4
4
|
export interface RollupPluginHtml extends Plugin {
|
|
5
5
|
api: {
|
|
6
6
|
getInputs(): InputData[];
|
|
7
|
-
addHtmlTransformer(transformHtmlFunction: TransformHtmlFunction
|
|
7
|
+
addHtmlTransformer(transformHtmlFunction: TransformHtmlFunction): void;
|
|
8
8
|
disableDefaultInject(): void;
|
|
9
9
|
addOutput(name: string): Plugin;
|
|
10
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollupPluginHTML.d.ts","sourceRoot":"","sources":["../src/rollupPluginHTML.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAEL,uBAAuB,EAEvB,qBAAqB,EACtB,MAAM,8BAA8B,CAAC;AAItC,MAAM,WAAW,gBAAiB,SAAQ,MAAM;IAC9C,GAAG,EAAE;QACH,SAAS,IAAI,SAAS,EAAE,CAAC;QACzB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"rollupPluginHTML.d.ts","sourceRoot":"","sources":["../src/rollupPluginHTML.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAEL,uBAAuB,EAEvB,qBAAqB,EACtB,MAAM,8BAA8B,CAAC;AAItC,MAAM,WAAW,gBAAiB,SAAQ,MAAM;IAC9C,GAAG,EAAE;QACH,SAAS,IAAI,SAAS,EAAE,CAAC;QACzB,kBAAkB,CAAC,qBAAqB,EAAE,qBAAqB,GAAG,IAAI,CAAC;QACvE,oBAAoB,IAAI,IAAI,CAAC;QAC7B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;KACjC,CAAC;CACH;AAED,wBAAgB,gBAAgB,CAAC,aAAa,GAAE,uBAA4B,GAAG,gBAAgB,CAsM9F"}
|
package/dist/rollupPluginHTML.js
CHANGED
|
@@ -14,8 +14,7 @@ function rollupPluginHTML(pluginOptions = {}) {
|
|
|
14
14
|
const multiOutputNames = [];
|
|
15
15
|
let inputs = [];
|
|
16
16
|
let generatedBundles = [];
|
|
17
|
-
let
|
|
18
|
-
let outputExternalTransformHtmlFns = [];
|
|
17
|
+
let externalTransformHtmlFns = [];
|
|
19
18
|
let defaultInjectDisabled = false;
|
|
20
19
|
let serviceWorkerPath = '';
|
|
21
20
|
let injectServiceWorker = false;
|
|
@@ -24,8 +23,7 @@ function rollupPluginHTML(pluginOptions = {}) {
|
|
|
24
23
|
function reset() {
|
|
25
24
|
inputs = [];
|
|
26
25
|
generatedBundles = [];
|
|
27
|
-
|
|
28
|
-
outputExternalTransformHtmlFns = [];
|
|
26
|
+
externalTransformHtmlFns = [];
|
|
29
27
|
}
|
|
30
28
|
return {
|
|
31
29
|
name: '@web/rollup-plugin-html',
|
|
@@ -53,7 +51,6 @@ function rollupPluginHTML(pluginOptions = {}) {
|
|
|
53
51
|
if (pluginOptions.strictCSPInlineScripts) {
|
|
54
52
|
strictCSPInlineScripts = pluginOptions.strictCSPInlineScripts;
|
|
55
53
|
}
|
|
56
|
-
pluginOptions.bundleAssetsFromCss = !!pluginOptions.bundleAssetsFromCss;
|
|
57
54
|
if (pluginOptions.input == null) {
|
|
58
55
|
// we are reading rollup input, so replace whatever was there
|
|
59
56
|
return Object.assign(Object.assign({}, inputOptions), { input: moduleImports.map(mod => mod.importPath) });
|
|
@@ -118,8 +115,7 @@ function rollupPluginHTML(pluginOptions = {}) {
|
|
|
118
115
|
inputs,
|
|
119
116
|
emittedAssets,
|
|
120
117
|
generatedBundles,
|
|
121
|
-
|
|
122
|
-
outputExternalTransformHtmlFns,
|
|
118
|
+
externalTransformHtmlFns,
|
|
123
119
|
pluginOptions,
|
|
124
120
|
defaultInjectDisabled,
|
|
125
121
|
serviceWorkerPath,
|
|
@@ -135,13 +131,8 @@ function rollupPluginHTML(pluginOptions = {}) {
|
|
|
135
131
|
getInputs() {
|
|
136
132
|
return inputs;
|
|
137
133
|
},
|
|
138
|
-
addHtmlTransformer(transformHtmlFunction
|
|
139
|
-
|
|
140
|
-
inputExternalTransformHtmlFns.push(transformHtmlFunction);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
outputExternalTransformHtmlFns.push(transformHtmlFunction);
|
|
144
|
-
}
|
|
134
|
+
addHtmlTransformer(transformHtmlFunction) {
|
|
135
|
+
externalTransformHtmlFns.push(transformHtmlFunction);
|
|
145
136
|
},
|
|
146
137
|
disableDefaultInject() {
|
|
147
138
|
defaultInjectDisabled = true;
|
|
@@ -170,8 +161,7 @@ function rollupPluginHTML(pluginOptions = {}) {
|
|
|
170
161
|
inputs,
|
|
171
162
|
emittedAssets,
|
|
172
163
|
generatedBundles,
|
|
173
|
-
|
|
174
|
-
outputExternalTransformHtmlFns,
|
|
164
|
+
externalTransformHtmlFns,
|
|
175
165
|
pluginOptions,
|
|
176
166
|
defaultInjectDisabled,
|
|
177
167
|
serviceWorkerPath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollupPluginHTML.js","sourceRoot":"","sources":["../src/rollupPluginHTML.ts"],"names":[],"mappings":";;;;;;AACA,gDAAwB;AAExB,iEAA2D;AAC3D,6DAAuD;AAEvD,sEAAgE;AAQhE,yCAAsD;AACtD,0DAAoD;
|
|
1
|
+
{"version":3,"file":"rollupPluginHTML.js","sourceRoot":"","sources":["../src/rollupPluginHTML.ts"],"names":[],"mappings":";;;;;;AACA,gDAAwB;AAExB,iEAA2D;AAC3D,6DAAuD;AAEvD,sEAAgE;AAQhE,yCAAsD;AACtD,0DAAoD;AAWpD,SAAgB,gBAAgB,CAAC,gBAAyC,EAAE;IAC1E,MAAM,gBAAgB,GAAa,EAAE,CAAC;IACtC,IAAI,MAAM,GAAgB,EAAE,CAAC;IAC7B,IAAI,gBAAgB,GAAsB,EAAE,CAAC;IAC7C,IAAI,wBAAwB,GAA4B,EAAE,CAAC;IAC3D,IAAI,qBAAqB,GAAG,KAAK,CAAC;IAClC,IAAI,iBAAiB,GAAG,EAAE,CAAC;IAC3B,IAAI,mBAAmB,GAAG,KAAK,CAAC;IAChC,IAAI,kBAA0B,CAAC;IAC/B,IAAI,sBAAsB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
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -52,8 +52,11 @@
|
|
|
52
52
|
"picomatch": "^2.2.2"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
+
"@prettier/sync": "^0.6.1",
|
|
55
56
|
"@types/html-minifier-terser": "^7.0.0",
|
|
56
57
|
"@types/picomatch": "^2.2.1",
|
|
58
|
+
"@types/prettier": "^3.0.0",
|
|
59
|
+
"prettier": "^3.6.2",
|
|
57
60
|
"rollup": "^4.4.0"
|
|
58
61
|
}
|
|
59
62
|
}
|
|
@@ -27,8 +27,8 @@ export interface RollupPluginHTMLOptions {
|
|
|
27
27
|
transformAsset?: TransformAssetFunction | TransformAssetFunction[];
|
|
28
28
|
/** Transform HTML file before output. */
|
|
29
29
|
transformHtml?: TransformHtmlFunction | TransformHtmlFunction[];
|
|
30
|
-
/** Whether to extract and bundle assets referenced in HTML. Defaults to true. */
|
|
31
|
-
extractAssets?: boolean;
|
|
30
|
+
/** Whether to extract and bundle assets referenced in HTML and CSS. Defaults to true. */
|
|
31
|
+
extractAssets?: boolean | 'legacy-html' | 'legacy-html-and-css';
|
|
32
32
|
/** Whether to ignore assets referenced in HTML and CSS with glob patterns. */
|
|
33
33
|
externalAssets?: string | string[];
|
|
34
34
|
/** Define a full absolute url to your site (e.g. https://domain.com) */
|
|
@@ -43,8 +43,6 @@ export interface RollupPluginHTMLOptions {
|
|
|
43
43
|
absolutePathPrefix?: string;
|
|
44
44
|
/** When set to true, will insert meta tags for CSP and add script-src values for inline scripts by sha256-hashing the contents */
|
|
45
45
|
strictCSPInlineScripts?: boolean;
|
|
46
|
-
/** Bundle assets reference from CSS via `url` */
|
|
47
|
-
bundleAssetsFromCss?: boolean;
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
export interface GeneratedBundle {
|
package/src/assets/utils.ts
CHANGED
|
@@ -5,8 +5,18 @@ import { findElements, getTagName, getAttribute } from '@web/parse5-utils';
|
|
|
5
5
|
import { createError } from '../utils.js';
|
|
6
6
|
import { serialize } from 'v8';
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
const assetLinkRels = [
|
|
9
|
+
'icon',
|
|
10
|
+
'apple-touch-icon',
|
|
11
|
+
'mask-icon',
|
|
12
|
+
'stylesheet',
|
|
13
|
+
'manifest',
|
|
14
|
+
'preload',
|
|
15
|
+
'prefetch',
|
|
16
|
+
'modulepreload',
|
|
17
|
+
];
|
|
18
|
+
const legacyHashedLinkRels = ['stylesheet'];
|
|
19
|
+
const assetMetaProperties = ['og:image'];
|
|
10
20
|
|
|
11
21
|
function getSrcSetUrls(srcset: string) {
|
|
12
22
|
if (!srcset) {
|
|
@@ -41,13 +51,14 @@ function isAsset(node: Element) {
|
|
|
41
51
|
path = extractFirstUrlOfSrcSet(node) ?? '';
|
|
42
52
|
}
|
|
43
53
|
break;
|
|
44
|
-
case 'link':
|
|
45
|
-
if (
|
|
54
|
+
case 'link': {
|
|
55
|
+
if (assetLinkRels.includes(getAttribute(node, 'rel') ?? '')) {
|
|
46
56
|
path = getAttribute(node, 'href') ?? '';
|
|
47
57
|
}
|
|
48
58
|
break;
|
|
59
|
+
}
|
|
49
60
|
case 'meta':
|
|
50
|
-
if (getAttribute(node, 'property')
|
|
61
|
+
if (assetMetaProperties.includes(getAttribute(node, 'property') ?? '')) {
|
|
51
62
|
path = getAttribute(node, 'content') ?? '';
|
|
52
63
|
}
|
|
53
64
|
break;
|
|
@@ -70,7 +81,10 @@ function isAsset(node: Element) {
|
|
|
70
81
|
}
|
|
71
82
|
}
|
|
72
83
|
|
|
73
|
-
export function isHashedAsset(
|
|
84
|
+
export function isHashedAsset(
|
|
85
|
+
node: Element,
|
|
86
|
+
extractAssets: boolean | 'legacy-html' | 'legacy-html-and-css',
|
|
87
|
+
) {
|
|
74
88
|
switch (getTagName(node)) {
|
|
75
89
|
case 'img':
|
|
76
90
|
return true;
|
|
@@ -78,8 +92,13 @@ export function isHashedAsset(node: Element) {
|
|
|
78
92
|
return true;
|
|
79
93
|
case 'script':
|
|
80
94
|
return true;
|
|
81
|
-
case 'link':
|
|
82
|
-
|
|
95
|
+
case 'link': {
|
|
96
|
+
if (extractAssets === 'legacy-html' || extractAssets === 'legacy-html-and-css') {
|
|
97
|
+
return legacyHashedLinkRels.includes(getAttribute(node, 'rel') ?? '');
|
|
98
|
+
} else {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
83
102
|
case 'meta':
|
|
84
103
|
return true;
|
|
85
104
|
default:
|
|
@@ -15,6 +15,7 @@ export interface ExtractAssetsParams {
|
|
|
15
15
|
htmlFilePath: string;
|
|
16
16
|
htmlDir: string;
|
|
17
17
|
rootDir: string;
|
|
18
|
+
extractAssets: boolean | 'legacy-html' | 'legacy-html-and-css';
|
|
18
19
|
externalAssets?: string | string[];
|
|
19
20
|
absolutePathPrefix?: string;
|
|
20
21
|
}
|
|
@@ -35,7 +36,7 @@ export function extractAssets(params: ExtractAssetsParams): InputAsset[] {
|
|
|
35
36
|
params.rootDir,
|
|
36
37
|
params.absolutePathPrefix,
|
|
37
38
|
);
|
|
38
|
-
const hashed = isHashedAsset(node);
|
|
39
|
+
const hashed = isHashedAsset(node, params.extractAssets);
|
|
39
40
|
const alreadyHandled = allAssets.find(a => a.filePath === filePath && a.hashed === hashed);
|
|
40
41
|
if (!alreadyHandled) {
|
|
41
42
|
try {
|
|
@@ -49,7 +50,7 @@ export function extractAssets(params: ExtractAssetsParams): InputAsset[] {
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
const content = fs.readFileSync(filePath);
|
|
52
|
-
allAssets.push({ filePath, hashed, content });
|
|
53
|
+
allAssets.push({ filePath, hashed: hashed, content });
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
}
|
|
@@ -7,7 +7,7 @@ export interface ExtractParams {
|
|
|
7
7
|
html: string;
|
|
8
8
|
htmlFilePath: string;
|
|
9
9
|
rootDir: string;
|
|
10
|
-
extractAssets: boolean;
|
|
10
|
+
extractAssets: boolean | 'legacy-html' | 'legacy-html-and-css';
|
|
11
11
|
externalAssets?: string | string[];
|
|
12
12
|
absolutePathPrefix?: string;
|
|
13
13
|
}
|
|
@@ -30,6 +30,7 @@ export function extractModulesAndAssets(params: ExtractParams) {
|
|
|
30
30
|
htmlDir,
|
|
31
31
|
htmlFilePath,
|
|
32
32
|
rootDir,
|
|
33
|
+
extractAssets: params.extractAssets,
|
|
33
34
|
externalAssets,
|
|
34
35
|
absolutePathPrefix,
|
|
35
36
|
})
|
|
@@ -30,14 +30,21 @@ export interface CreateInputDataParams {
|
|
|
30
30
|
html: string;
|
|
31
31
|
rootDir: string;
|
|
32
32
|
filePath?: string;
|
|
33
|
-
extractAssets: boolean;
|
|
33
|
+
extractAssets: boolean | 'legacy-html' | 'legacy-html-and-css';
|
|
34
34
|
externalAssets?: string | string[];
|
|
35
35
|
absolutePathPrefix?: string;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function createInputData(params: CreateInputDataParams): InputData {
|
|
39
|
-
const {
|
|
40
|
-
|
|
39
|
+
const {
|
|
40
|
+
name,
|
|
41
|
+
html,
|
|
42
|
+
rootDir,
|
|
43
|
+
filePath,
|
|
44
|
+
extractAssets = true,
|
|
45
|
+
externalAssets,
|
|
46
|
+
absolutePathPrefix,
|
|
47
|
+
} = params;
|
|
41
48
|
const htmlFilePath = filePath ? filePath : path.resolve(rootDir, name);
|
|
42
49
|
const result = extractModulesAndAssets({
|
|
43
50
|
html,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
1
2
|
import { getEntrypointBundles } from './getEntrypointBundles.js';
|
|
2
3
|
import { getOutputHTML } from './getOutputHTML.js';
|
|
3
4
|
import { createError } from '../utils.js';
|
|
@@ -15,8 +16,7 @@ export interface CreateHTMLAssetParams {
|
|
|
15
16
|
input: InputData;
|
|
16
17
|
emittedAssets: EmittedAssets;
|
|
17
18
|
generatedBundles: GeneratedBundle[];
|
|
18
|
-
|
|
19
|
-
outputExternalTransformHtmlFns: TransformHtmlFunction[];
|
|
19
|
+
externalTransformHtmlFns: TransformHtmlFunction[];
|
|
20
20
|
pluginOptions: RollupPluginHTMLOptions;
|
|
21
21
|
defaultInjectDisabled: boolean;
|
|
22
22
|
serviceWorkerPath: string;
|
|
@@ -31,8 +31,7 @@ export async function createHTMLAsset(params: CreateHTMLAssetParams): Promise<Em
|
|
|
31
31
|
input,
|
|
32
32
|
emittedAssets,
|
|
33
33
|
generatedBundles,
|
|
34
|
-
|
|
35
|
-
outputExternalTransformHtmlFns,
|
|
34
|
+
externalTransformHtmlFns,
|
|
36
35
|
pluginOptions,
|
|
37
36
|
defaultInjectDisabled,
|
|
38
37
|
serviceWorkerPath,
|
|
@@ -59,8 +58,7 @@ export async function createHTMLAsset(params: CreateHTMLAssetParams): Promise<Em
|
|
|
59
58
|
input,
|
|
60
59
|
outputDir,
|
|
61
60
|
emittedAssets,
|
|
62
|
-
|
|
63
|
-
outputExternalTransformHtmlFns,
|
|
61
|
+
externalTransformHtmlFns,
|
|
64
62
|
defaultInjectDisabled,
|
|
65
63
|
serviceWorkerPath,
|
|
66
64
|
injectServiceWorker,
|
|
@@ -68,7 +66,14 @@ export async function createHTMLAsset(params: CreateHTMLAssetParams): Promise<Em
|
|
|
68
66
|
strictCSPInlineScripts,
|
|
69
67
|
});
|
|
70
68
|
|
|
71
|
-
|
|
69
|
+
const normalizedInputName = input.name.split(path.sep).join('/');
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
fileName: normalizedInputName,
|
|
73
|
+
name: normalizedInputName,
|
|
74
|
+
source: outputHtml,
|
|
75
|
+
type: 'asset',
|
|
76
|
+
};
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
export interface CreateHTMLAssetsParams {
|
|
@@ -76,8 +81,7 @@ export interface CreateHTMLAssetsParams {
|
|
|
76
81
|
inputs: InputData[];
|
|
77
82
|
emittedAssets: EmittedAssets;
|
|
78
83
|
generatedBundles: GeneratedBundle[];
|
|
79
|
-
|
|
80
|
-
outputExternalTransformHtmlFns: TransformHtmlFunction[];
|
|
84
|
+
externalTransformHtmlFns: TransformHtmlFunction[];
|
|
81
85
|
pluginOptions: RollupPluginHTMLOptions;
|
|
82
86
|
defaultInjectDisabled: boolean;
|
|
83
87
|
serviceWorkerPath: string;
|
package/src/output/emitAssets.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { transform } from 'lightningcss';
|
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
|
|
6
6
|
import { InputAsset, InputData } from '../input/InputData';
|
|
7
|
+
import { toBrowserPath } from './utils.js';
|
|
7
8
|
import { createAssetPicomatchMatcher } from '../assets/utils.js';
|
|
8
9
|
import { RollupPluginHTMLOptions, TransformAssetFunction } from '../RollupPluginHTMLOptions';
|
|
9
10
|
|
|
@@ -39,6 +40,8 @@ export async function emitAssets(
|
|
|
39
40
|
inputs: InputData[],
|
|
40
41
|
options: RollupPluginHTMLOptions,
|
|
41
42
|
) {
|
|
43
|
+
const extractAssets = options.extractAssets ?? true;
|
|
44
|
+
const extractAssetsLegacyCss = options.extractAssets === 'legacy-html-and-css';
|
|
42
45
|
const emittedStaticAssets = new Map<string, string>();
|
|
43
46
|
const emittedHashedAssets = new Map<string, string>();
|
|
44
47
|
const emittedStaticAssetNames = new Set();
|
|
@@ -85,7 +88,7 @@ export async function emitAssets(
|
|
|
85
88
|
const isExternal = createAssetPicomatchMatcher(options.externalAssets);
|
|
86
89
|
const emittedExternalAssets = new Map();
|
|
87
90
|
if (asset.hashed) {
|
|
88
|
-
if (basename.endsWith('.css') &&
|
|
91
|
+
if (basename.endsWith('.css') && extractAssets) {
|
|
89
92
|
let updatedCssSource = false;
|
|
90
93
|
const { code } = await transform({
|
|
91
94
|
filename: basename,
|
|
@@ -104,22 +107,47 @@ export async function emitAssets(
|
|
|
104
107
|
|
|
105
108
|
// Avoid duplicates
|
|
106
109
|
if (!emittedExternalAssets.has(assetLocation)) {
|
|
107
|
-
const
|
|
110
|
+
const basename = path.basename(filePath);
|
|
111
|
+
const fileRef = this.emitFile({
|
|
108
112
|
type: 'asset',
|
|
109
|
-
name:
|
|
113
|
+
name: extractAssetsLegacyCss ? `assets/${basename}` : basename,
|
|
110
114
|
source: assetContent,
|
|
111
115
|
});
|
|
112
|
-
const
|
|
113
|
-
|
|
116
|
+
const emittedAssetFilepath = this.getFileName(fileRef);
|
|
117
|
+
const emittedAssetBasename = path.basename(emittedAssetFilepath);
|
|
118
|
+
emittedExternalAssets.set(assetLocation, emittedAssetFilepath);
|
|
114
119
|
// Update the URL in the original CSS file to point to the emitted asset file
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
120
|
+
if (extractAssetsLegacyCss) {
|
|
121
|
+
url.url = `assets/${emittedAssetBasename}`;
|
|
122
|
+
} else {
|
|
123
|
+
if (options.publicPath) {
|
|
124
|
+
url.url = toBrowserPath(
|
|
125
|
+
path.join(options.publicPath, emittedAssetFilepath),
|
|
126
|
+
);
|
|
127
|
+
} else {
|
|
128
|
+
url.url = emittedAssetBasename;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (idRef) {
|
|
132
|
+
url.url = `${url.url}#${idRef}`;
|
|
133
|
+
}
|
|
118
134
|
} else {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
135
|
+
const emittedAssetFilepath = emittedExternalAssets.get(assetLocation);
|
|
136
|
+
const emittedAssetBasename = path.basename(emittedAssetFilepath);
|
|
137
|
+
if (extractAssetsLegacyCss) {
|
|
138
|
+
url.url = `assets/${emittedAssetBasename}`;
|
|
139
|
+
} else {
|
|
140
|
+
if (options.publicPath) {
|
|
141
|
+
url.url = toBrowserPath(
|
|
142
|
+
path.join(options.publicPath, emittedAssetFilepath),
|
|
143
|
+
);
|
|
144
|
+
} else {
|
|
145
|
+
url.url = emittedAssetBasename;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (idRef) {
|
|
149
|
+
url.url = `${url.url}#${idRef}`;
|
|
150
|
+
}
|
|
123
151
|
}
|
|
124
152
|
}
|
|
125
153
|
updatedCssSource = true;
|
|
@@ -19,8 +19,7 @@ export interface GetOutputHTMLParams {
|
|
|
19
19
|
emittedAssets: EmittedAssets;
|
|
20
20
|
pluginOptions: RollupPluginHTMLOptions;
|
|
21
21
|
entrypointBundles: Record<string, EntrypointBundle>;
|
|
22
|
-
|
|
23
|
-
outputExternalTransformHtmlFns?: TransformHtmlFunction[];
|
|
22
|
+
externalTransformHtmlFns?: TransformHtmlFunction[];
|
|
24
23
|
defaultInjectDisabled: boolean;
|
|
25
24
|
serviceWorkerPath: string;
|
|
26
25
|
injectServiceWorker: boolean;
|
|
@@ -32,8 +31,7 @@ export async function getOutputHTML(params: GetOutputHTMLParams) {
|
|
|
32
31
|
const {
|
|
33
32
|
pluginOptions,
|
|
34
33
|
entrypointBundles,
|
|
35
|
-
|
|
36
|
-
outputExternalTransformHtmlFns,
|
|
34
|
+
externalTransformHtmlFns,
|
|
37
35
|
input,
|
|
38
36
|
outputDir,
|
|
39
37
|
emittedAssets,
|
|
@@ -46,20 +44,8 @@ export async function getOutputHTML(params: GetOutputHTMLParams) {
|
|
|
46
44
|
const { default: defaultBundle, ...multiBundles } = entrypointBundles;
|
|
47
45
|
const { absoluteSocialMediaUrls = true, rootDir = process.cwd() } = pluginOptions;
|
|
48
46
|
|
|
49
|
-
let inputHtml = input.html;
|
|
50
|
-
|
|
51
|
-
// run transform functions on input HTML
|
|
52
|
-
const inputTransforms = [...(inputExternalTransformHtmlFns ?? [])];
|
|
53
|
-
for (const transform of inputTransforms) {
|
|
54
|
-
inputHtml = await transform(inputHtml, {
|
|
55
|
-
bundle: defaultBundle,
|
|
56
|
-
bundles: multiBundles,
|
|
57
|
-
htmlFileName: input.name,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
47
|
// inject rollup output into HTML
|
|
62
|
-
let document = parse(
|
|
48
|
+
let document = parse(input.html);
|
|
63
49
|
if (pluginOptions.extractAssets !== false) {
|
|
64
50
|
injectedUpdatedAssetPaths({
|
|
65
51
|
document,
|
|
@@ -67,6 +53,7 @@ export async function getOutputHTML(params: GetOutputHTMLParams) {
|
|
|
67
53
|
outputDir,
|
|
68
54
|
rootDir,
|
|
69
55
|
emittedAssets,
|
|
56
|
+
extractAssets: pluginOptions.extractAssets,
|
|
70
57
|
externalAssets: pluginOptions.externalAssets,
|
|
71
58
|
absolutePathPrefix,
|
|
72
59
|
publicPath: pluginOptions.publicPath,
|
|
@@ -89,17 +76,17 @@ export async function getOutputHTML(params: GetOutputHTMLParams) {
|
|
|
89
76
|
|
|
90
77
|
let outputHtml = serialize(document);
|
|
91
78
|
|
|
92
|
-
const
|
|
79
|
+
const transforms = [...(externalTransformHtmlFns ?? [])];
|
|
93
80
|
if (pluginOptions.transformHtml) {
|
|
94
81
|
if (Array.isArray(pluginOptions.transformHtml)) {
|
|
95
|
-
|
|
82
|
+
transforms.push(...pluginOptions.transformHtml);
|
|
96
83
|
} else {
|
|
97
|
-
|
|
84
|
+
transforms.push(pluginOptions.transformHtml);
|
|
98
85
|
}
|
|
99
86
|
}
|
|
100
87
|
|
|
101
88
|
// run transform functions on output HTML
|
|
102
|
-
for (const transform of
|
|
89
|
+
for (const transform of transforms) {
|
|
103
90
|
outputHtml = await transform(outputHtml, {
|
|
104
91
|
bundle: defaultBundle,
|
|
105
92
|
bundles: multiBundles,
|
|
@@ -21,6 +21,7 @@ export interface InjectUpdatedAssetPathsArgs {
|
|
|
21
21
|
outputDir: string;
|
|
22
22
|
rootDir: string;
|
|
23
23
|
emittedAssets: EmittedAssets;
|
|
24
|
+
extractAssets?: boolean | 'legacy-html' | 'legacy-html-and-css';
|
|
24
25
|
externalAssets?: string | string[];
|
|
25
26
|
publicPath?: string;
|
|
26
27
|
absolutePathPrefix?: string;
|
|
@@ -44,6 +45,7 @@ export function injectedUpdatedAssetPaths(args: InjectUpdatedAssetPathsArgs) {
|
|
|
44
45
|
outputDir,
|
|
45
46
|
rootDir,
|
|
46
47
|
emittedAssets,
|
|
48
|
+
extractAssets = true,
|
|
47
49
|
externalAssets,
|
|
48
50
|
publicPath = './',
|
|
49
51
|
absolutePathPrefix,
|
|
@@ -59,7 +61,9 @@ export function injectedUpdatedAssetPaths(args: InjectUpdatedAssetPathsArgs) {
|
|
|
59
61
|
const htmlFilePath = input.filePath ? input.filePath : path.join(rootDir, input.name);
|
|
60
62
|
const htmlDir = path.dirname(htmlFilePath);
|
|
61
63
|
const filePath = resolveAssetFilePath(sourcePath, htmlDir, rootDir, absolutePathPrefix);
|
|
62
|
-
const assetPaths = isHashedAsset(node)
|
|
64
|
+
const assetPaths = isHashedAsset(node, extractAssets)
|
|
65
|
+
? emittedAssets.hashed
|
|
66
|
+
: emittedAssets.static;
|
|
63
67
|
const relativeOutputPath = assetPaths.get(filePath);
|
|
64
68
|
|
|
65
69
|
if (!relativeOutputPath) {
|
package/src/rollupPluginHTML.ts
CHANGED
|
@@ -18,10 +18,7 @@ import { emitAssets } from './output/emitAssets.js';
|
|
|
18
18
|
export interface RollupPluginHtml extends Plugin {
|
|
19
19
|
api: {
|
|
20
20
|
getInputs(): InputData[];
|
|
21
|
-
addHtmlTransformer(
|
|
22
|
-
transformHtmlFunction: TransformHtmlFunction,
|
|
23
|
-
transformStage?: 'input' | 'output',
|
|
24
|
-
): void;
|
|
21
|
+
addHtmlTransformer(transformHtmlFunction: TransformHtmlFunction): void;
|
|
25
22
|
disableDefaultInject(): void;
|
|
26
23
|
addOutput(name: string): Plugin;
|
|
27
24
|
};
|
|
@@ -31,8 +28,7 @@ export function rollupPluginHTML(pluginOptions: RollupPluginHTMLOptions = {}): R
|
|
|
31
28
|
const multiOutputNames: string[] = [];
|
|
32
29
|
let inputs: InputData[] = [];
|
|
33
30
|
let generatedBundles: GeneratedBundle[] = [];
|
|
34
|
-
let
|
|
35
|
-
let outputExternalTransformHtmlFns: TransformHtmlFunction[] = [];
|
|
31
|
+
let externalTransformHtmlFns: TransformHtmlFunction[] = [];
|
|
36
32
|
let defaultInjectDisabled = false;
|
|
37
33
|
let serviceWorkerPath = '';
|
|
38
34
|
let injectServiceWorker = false;
|
|
@@ -42,8 +38,7 @@ export function rollupPluginHTML(pluginOptions: RollupPluginHTMLOptions = {}): R
|
|
|
42
38
|
function reset() {
|
|
43
39
|
inputs = [];
|
|
44
40
|
generatedBundles = [];
|
|
45
|
-
|
|
46
|
-
outputExternalTransformHtmlFns = [];
|
|
41
|
+
externalTransformHtmlFns = [];
|
|
47
42
|
}
|
|
48
43
|
|
|
49
44
|
return {
|
|
@@ -77,7 +72,6 @@ export function rollupPluginHTML(pluginOptions: RollupPluginHTMLOptions = {}): R
|
|
|
77
72
|
if (pluginOptions.strictCSPInlineScripts) {
|
|
78
73
|
strictCSPInlineScripts = pluginOptions.strictCSPInlineScripts;
|
|
79
74
|
}
|
|
80
|
-
pluginOptions.bundleAssetsFromCss = !!pluginOptions.bundleAssetsFromCss;
|
|
81
75
|
|
|
82
76
|
if (pluginOptions.input == null) {
|
|
83
77
|
// we are reading rollup input, so replace whatever was there
|
|
@@ -151,8 +145,7 @@ export function rollupPluginHTML(pluginOptions: RollupPluginHTMLOptions = {}): R
|
|
|
151
145
|
inputs,
|
|
152
146
|
emittedAssets,
|
|
153
147
|
generatedBundles,
|
|
154
|
-
|
|
155
|
-
outputExternalTransformHtmlFns,
|
|
148
|
+
externalTransformHtmlFns,
|
|
156
149
|
pluginOptions,
|
|
157
150
|
defaultInjectDisabled,
|
|
158
151
|
serviceWorkerPath,
|
|
@@ -171,15 +164,8 @@ export function rollupPluginHTML(pluginOptions: RollupPluginHTMLOptions = {}): R
|
|
|
171
164
|
return inputs;
|
|
172
165
|
},
|
|
173
166
|
|
|
174
|
-
addHtmlTransformer(
|
|
175
|
-
transformHtmlFunction
|
|
176
|
-
transformStage: 'input' | 'output' = 'output',
|
|
177
|
-
) {
|
|
178
|
-
if (transformStage === 'input') {
|
|
179
|
-
inputExternalTransformHtmlFns.push(transformHtmlFunction);
|
|
180
|
-
} else {
|
|
181
|
-
outputExternalTransformHtmlFns.push(transformHtmlFunction);
|
|
182
|
-
}
|
|
167
|
+
addHtmlTransformer(transformHtmlFunction: TransformHtmlFunction) {
|
|
168
|
+
externalTransformHtmlFns.push(transformHtmlFunction);
|
|
183
169
|
},
|
|
184
170
|
|
|
185
171
|
disableDefaultInject() {
|
|
@@ -218,8 +204,7 @@ export function rollupPluginHTML(pluginOptions: RollupPluginHTMLOptions = {}): R
|
|
|
218
204
|
inputs,
|
|
219
205
|
emittedAssets,
|
|
220
206
|
generatedBundles,
|
|
221
|
-
|
|
222
|
-
outputExternalTransformHtmlFns,
|
|
207
|
+
externalTransformHtmlFns,
|
|
223
208
|
pluginOptions,
|
|
224
209
|
defaultInjectDisabled,
|
|
225
210
|
serviceWorkerPath,
|