@web/rollup-plugin-html 0.0.0-canary-20230316175616
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 +5 -0
- package/dist/RollupPluginHTMLOptions.d.ts +68 -0
- package/dist/RollupPluginHTMLOptions.d.ts.map +1 -0
- package/dist/RollupPluginHTMLOptions.js +3 -0
- package/dist/RollupPluginHTMLOptions.js.map +1 -0
- package/dist/assets/utils.d.ts +7 -0
- package/dist/assets/utils.d.ts.map +1 -0
- package/dist/assets/utils.js +138 -0
- package/dist/assets/utils.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/input/InputData.d.ts +16 -0
- package/dist/input/InputData.d.ts.map +1 -0
- package/dist/input/InputData.js +3 -0
- package/dist/input/InputData.js.map +1 -0
- package/dist/input/addRollupInput.d.ts +4 -0
- package/dist/input/addRollupInput.d.ts.map +1 -0
- package/dist/input/addRollupInput.js +36 -0
- package/dist/input/addRollupInput.js.map +1 -0
- package/dist/input/extract/extractAssets.d.ts +11 -0
- package/dist/input/extract/extractAssets.d.ts.map +1 -0
- package/dist/input/extract/extractAssets.js +37 -0
- package/dist/input/extract/extractAssets.js.map +1 -0
- package/dist/input/extract/extractModules.d.ts +13 -0
- package/dist/input/extract/extractModules.d.ts.map +1 -0
- package/dist/input/extract/extractModules.js +68 -0
- package/dist/input/extract/extractModules.js.map +1 -0
- package/dist/input/extract/extractModulesAndAssets.d.ts +14 -0
- package/dist/input/extract/extractModulesAndAssets.d.ts.map +1 -0
- package/dist/input/extract/extractModulesAndAssets.js +30 -0
- package/dist/input/extract/extractModulesAndAssets.js.map +1 -0
- package/dist/input/getInputData.d.ts +13 -0
- package/dist/input/getInputData.d.ts.map +1 -0
- package/dist/input/getInputData.js +94 -0
- package/dist/input/getInputData.js.map +1 -0
- package/dist/input/normalizeInputOptions.d.ts +4 -0
- package/dist/input/normalizeInputOptions.d.ts.map +1 -0
- package/dist/input/normalizeInputOptions.js +38 -0
- package/dist/input/normalizeInputOptions.js.map +1 -0
- package/dist/output/createHTMLOutput.d.ts +33 -0
- package/dist/output/createHTMLOutput.d.ts.map +1 -0
- package/dist/output/createHTMLOutput.js +39 -0
- package/dist/output/createHTMLOutput.js.map +1 -0
- package/dist/output/emitAssets.d.ts +12 -0
- package/dist/output/emitAssets.d.ts.map +1 -0
- package/dist/output/emitAssets.js +69 -0
- package/dist/output/emitAssets.js.map +1 -0
- package/dist/output/getEntrypointBundles.d.ts +18 -0
- package/dist/output/getEntrypointBundles.d.ts.map +1 -0
- package/dist/output/getEntrypointBundles.js +59 -0
- package/dist/output/getEntrypointBundles.js.map +1 -0
- package/dist/output/getOutputHTML.d.ts +18 -0
- package/dist/output/getOutputHTML.d.ts.map +1 -0
- package/dist/output/getOutputHTML.js +91 -0
- package/dist/output/getOutputHTML.js.map +1 -0
- package/dist/output/hashInlineScripts.d.ts +3 -0
- package/dist/output/hashInlineScripts.d.ts.map +1 -0
- package/dist/output/hashInlineScripts.js +131 -0
- package/dist/output/hashInlineScripts.js.map +1 -0
- package/dist/output/injectAbsoluteBaseUrl.d.ts +3 -0
- package/dist/output/injectAbsoluteBaseUrl.d.ts.map +1 -0
- package/dist/output/injectAbsoluteBaseUrl.js +37 -0
- package/dist/output/injectAbsoluteBaseUrl.js.map +1 -0
- package/dist/output/injectBundles.d.ts +5 -0
- package/dist/output/injectBundles.d.ts.map +1 -0
- package/dist/output/injectBundles.js +36 -0
- package/dist/output/injectBundles.js.map +1 -0
- package/dist/output/injectServiceWorkerRegistration.d.ts +9 -0
- package/dist/output/injectServiceWorkerRegistration.d.ts.map +1 -0
- package/dist/output/injectServiceWorkerRegistration.js +37 -0
- package/dist/output/injectServiceWorkerRegistration.js.map +1 -0
- package/dist/output/injectedUpdatedAssetPaths.d.ts +14 -0
- package/dist/output/injectedUpdatedAssetPaths.d.ts.map +1 -0
- package/dist/output/injectedUpdatedAssetPaths.js +60 -0
- package/dist/output/injectedUpdatedAssetPaths.js.map +1 -0
- package/dist/output/utils.d.ts +2 -0
- package/dist/output/utils.d.ts.map +1 -0
- package/dist/output/utils.js +12 -0
- package/dist/output/utils.js.map +1 -0
- package/dist/rollupPluginHTML.d.ts +13 -0
- package/dist/rollupPluginHTML.d.ts.map +1 -0
- package/dist/rollupPluginHTML.js +183 -0
- package/dist/rollupPluginHTML.js.map +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +10 -0
- package/dist/utils.js.map +1 -0
- package/index.mjs +6 -0
- package/package.json +55 -0
- package/src/RollupPluginHTMLOptions.ts +92 -0
- package/src/assets/utils.ts +145 -0
- package/src/index.ts +14 -0
- package/src/input/InputData.ts +16 -0
- package/src/input/addRollupInput.ts +55 -0
- package/src/input/extract/extractAssets.ts +53 -0
- package/src/input/extract/extractModules.ts +78 -0
- package/src/input/extract/extractModulesAndAssets.ts +34 -0
- package/src/input/getInputData.ts +120 -0
- package/src/input/normalizeInputOptions.ts +47 -0
- package/src/output/createHTMLOutput.ts +87 -0
- package/src/output/emitAssets.ts +80 -0
- package/src/output/getEntrypointBundles.ts +88 -0
- package/src/output/getOutputHTML.ts +115 -0
- package/src/output/hashInlineScripts.ts +153 -0
- package/src/output/injectAbsoluteBaseUrl.ts +41 -0
- package/src/output/injectBundles.ts +44 -0
- package/src/output/injectServiceWorkerRegistration.ts +48 -0
- package/src/output/injectedUpdatedAssetPaths.ts +89 -0
- package/src/output/utils.ts +5 -0
- package/src/rollupPluginHTML.ts +225 -0
- package/src/utils.ts +9 -0
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { OutputChunk, OutputOptions, OutputBundle } from 'rollup';
|
|
3
|
+
import { Attribute } from 'parse5';
|
|
4
|
+
export interface InputHTMLOptions {
|
|
5
|
+
/** The html source code. If set, overwrites path. */
|
|
6
|
+
html?: string;
|
|
7
|
+
/** Name of the HTML files when using the html option. */
|
|
8
|
+
name?: string;
|
|
9
|
+
/** Path to the HTML file, or glob to multiple HTML files. */
|
|
10
|
+
path?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface RollupPluginHTMLOptions {
|
|
13
|
+
/** HTML file(s) to use as input. If not set, uses rollup input option. */
|
|
14
|
+
input?: string | InputHTMLOptions | (string | InputHTMLOptions)[];
|
|
15
|
+
/** HTML file glob pattern or patterns to ignore */
|
|
16
|
+
exclude?: string | string[];
|
|
17
|
+
/** Whether to minify the output HTML. */
|
|
18
|
+
minify?: boolean;
|
|
19
|
+
/** Whether to preserve or flatten the directory structure of the HTML file. */
|
|
20
|
+
flattenOutput?: boolean;
|
|
21
|
+
/** Directory to resolve absolute paths relative to, and to use as base for non-flatted filename output. */
|
|
22
|
+
rootDir?: string;
|
|
23
|
+
/** Path to load modules and assets from at runtime. */
|
|
24
|
+
publicPath?: string;
|
|
25
|
+
/** Transform asset source before output. */
|
|
26
|
+
transformAsset?: TransformAssetFunction | TransformAssetFunction[];
|
|
27
|
+
/** Transform HTML file before output. */
|
|
28
|
+
transformHtml?: TransformHtmlFunction | TransformHtmlFunction[];
|
|
29
|
+
/** Whether to extract and bundle assets referenced in HTML. Defaults to true. */
|
|
30
|
+
extractAssets?: boolean;
|
|
31
|
+
/** Define a full absolute url to your site (e.g. https://domain.com) */
|
|
32
|
+
absoluteBaseUrl?: string;
|
|
33
|
+
/** Whether to set full absolute urls for ['meta[property=og:image]', 'link[rel=canonical]', 'meta[property=og:url]'] or not. Requires a absoluteBaseUrl to be set. Default to true. */
|
|
34
|
+
absoluteSocialMediaUrls?: boolean;
|
|
35
|
+
/** Should a service worker registration script be injected. Defaults to false. */
|
|
36
|
+
injectServiceWorker?: boolean;
|
|
37
|
+
/** File system path to the generated service worker file */
|
|
38
|
+
serviceWorkerPath?: string;
|
|
39
|
+
/** Prefix to strip from absolute paths when resolving assets and scripts, for example when using a base path that does not exist on disk. */
|
|
40
|
+
absolutePathPrefix?: string;
|
|
41
|
+
/** When set to true, will insert meta tags for CSP and add script-src values for inline scripts by sha256-hashing the contents */
|
|
42
|
+
strictCSPInlineScripts?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface GeneratedBundle {
|
|
45
|
+
name: string;
|
|
46
|
+
options: OutputOptions;
|
|
47
|
+
bundle: OutputBundle;
|
|
48
|
+
}
|
|
49
|
+
export interface ScriptModuleTag {
|
|
50
|
+
importPath: string;
|
|
51
|
+
attributes?: Attribute[];
|
|
52
|
+
code?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface EntrypointBundle extends GeneratedBundle {
|
|
55
|
+
entrypoints: {
|
|
56
|
+
importPath: string;
|
|
57
|
+
chunk: OutputChunk;
|
|
58
|
+
attributes?: Attribute[];
|
|
59
|
+
}[];
|
|
60
|
+
}
|
|
61
|
+
export interface TransformHtmlArgs {
|
|
62
|
+
bundle: EntrypointBundle;
|
|
63
|
+
bundles: Record<string, EntrypointBundle>;
|
|
64
|
+
htmlFileName: string;
|
|
65
|
+
}
|
|
66
|
+
export declare type TransformHtmlFunction = (html: string, args: TransformHtmlArgs) => string | Promise<string>;
|
|
67
|
+
export declare type TransformAssetFunction = (content: Buffer, filePath: string) => string | Buffer | Promise<string | Buffer>;
|
|
68
|
+
//# sourceMappingURL=RollupPluginHTMLOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RollupPluginHTMLOptions.d.ts","sourceRoot":"","sources":["../src/RollupPluginHTMLOptions.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,MAAM,WAAW,gBAAgB;IAC/B,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6DAA6D;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f;AAED,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,WAAW,EAAE;QAGX,UAAU,EAAE,MAAM,CAAC;QAGnB,KAAK,EAAE,WAAW,CAAC;QACnB,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;KAC1B,EAAE,CAAC;CACL;AAED,MAAM,WAAW,iBAAiB;IAOhC,MAAM,EAAE,gBAAgB,CAAC;IAGzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC1C,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,oBAAY,qBAAqB,GAAG,CAClC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,iBAAiB,KACpB,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE9B,oBAAY,sBAAsB,GAAG,CACnC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,KACb,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RollupPluginHTMLOptions.js","sourceRoot":"","sources":["../src/RollupPluginHTMLOptions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Document, Element } from 'parse5';
|
|
2
|
+
export declare function isHashedAsset(node: Element): boolean;
|
|
3
|
+
export declare function resolveAssetFilePath(browserPath: string, htmlDir: string, projectRootDir: string, absolutePathPrefix?: string): string;
|
|
4
|
+
export declare function getSourceAttribute(node: Element): "srcset" | "src" | "href" | "content";
|
|
5
|
+
export declare function getSourcePaths(node: Element): string[];
|
|
6
|
+
export declare function findAssets(document: Document): Element[];
|
|
7
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/assets/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAuE3C,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,WAe1C;AAED,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,kBAAkB,CAAC,EAAE,MAAM,UAU5B;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,yCAoB/C;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,YAc3C;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,aAE5C"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.findAssets = exports.getSourcePaths = exports.getSourceAttribute = exports.resolveAssetFilePath = exports.isHashedAsset = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const parse5_utils_1 = require("@web/parse5-utils");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const v8_1 = require("v8");
|
|
11
|
+
const hashedLinkRels = ['stylesheet'];
|
|
12
|
+
const linkRels = [...hashedLinkRels, 'icon', 'manifest', 'apple-touch-icon', 'mask-icon'];
|
|
13
|
+
function getSrcSetUrls(srcset) {
|
|
14
|
+
if (!srcset) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
const srcsetParts = srcset.includes(',') ? srcset.split(',') : [srcset];
|
|
18
|
+
const urls = srcsetParts
|
|
19
|
+
.map(url => url.trim())
|
|
20
|
+
.map(url => (url.includes(' ') ? url.split(' ')[0] : url));
|
|
21
|
+
return urls;
|
|
22
|
+
}
|
|
23
|
+
function extractFirstUrlOfSrcSet(node) {
|
|
24
|
+
const srcset = parse5_utils_1.getAttribute(node, 'srcset');
|
|
25
|
+
if (!srcset) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
const urls = getSrcSetUrls(srcset);
|
|
29
|
+
return urls[0];
|
|
30
|
+
}
|
|
31
|
+
function isAsset(node) {
|
|
32
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
33
|
+
let path = '';
|
|
34
|
+
switch (parse5_utils_1.getTagName(node)) {
|
|
35
|
+
case 'img':
|
|
36
|
+
path = (_a = parse5_utils_1.getAttribute(node, 'src')) !== null && _a !== void 0 ? _a : '';
|
|
37
|
+
break;
|
|
38
|
+
case 'source':
|
|
39
|
+
if (parse5_utils_1.getAttribute(node, 'src')) {
|
|
40
|
+
path = (_b = parse5_utils_1.getAttribute(node, 'src')) !== null && _b !== void 0 ? _b : '';
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
path = (_c = extractFirstUrlOfSrcSet(node)) !== null && _c !== void 0 ? _c : '';
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case 'link':
|
|
47
|
+
if (linkRels.includes((_d = parse5_utils_1.getAttribute(node, 'rel')) !== null && _d !== void 0 ? _d : '')) {
|
|
48
|
+
path = (_e = parse5_utils_1.getAttribute(node, 'href')) !== null && _e !== void 0 ? _e : '';
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case 'meta':
|
|
52
|
+
if (parse5_utils_1.getAttribute(node, 'property') === 'og:image' && parse5_utils_1.getAttribute(node, 'content')) {
|
|
53
|
+
path = (_f = parse5_utils_1.getAttribute(node, 'content')) !== null && _f !== void 0 ? _f : '';
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case 'script':
|
|
57
|
+
if (parse5_utils_1.getAttribute(node, 'type') !== 'module' && parse5_utils_1.getAttribute(node, 'src')) {
|
|
58
|
+
path = (_g = parse5_utils_1.getAttribute(node, 'src')) !== null && _g !== void 0 ? _g : '';
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
default:
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (!path) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
new URL(path);
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function isHashedAsset(node) {
|
|
76
|
+
switch (parse5_utils_1.getTagName(node)) {
|
|
77
|
+
case 'img':
|
|
78
|
+
return true;
|
|
79
|
+
case 'source':
|
|
80
|
+
return true;
|
|
81
|
+
case 'script':
|
|
82
|
+
return true;
|
|
83
|
+
case 'link':
|
|
84
|
+
return hashedLinkRels.includes(parse5_utils_1.getAttribute(node, 'rel'));
|
|
85
|
+
case 'meta':
|
|
86
|
+
return true;
|
|
87
|
+
default:
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.isHashedAsset = isHashedAsset;
|
|
92
|
+
function resolveAssetFilePath(browserPath, htmlDir, projectRootDir, absolutePathPrefix) {
|
|
93
|
+
const _browserPath = absolutePathPrefix && browserPath[0] === '/'
|
|
94
|
+
? '/' + path_1.default.posix.relative(absolutePathPrefix, browserPath)
|
|
95
|
+
: browserPath;
|
|
96
|
+
return path_1.default.join(_browserPath.startsWith('/') ? projectRootDir : htmlDir, _browserPath.split('/').join(path_1.default.sep));
|
|
97
|
+
}
|
|
98
|
+
exports.resolveAssetFilePath = resolveAssetFilePath;
|
|
99
|
+
function getSourceAttribute(node) {
|
|
100
|
+
switch (parse5_utils_1.getTagName(node)) {
|
|
101
|
+
case 'img': {
|
|
102
|
+
return 'src';
|
|
103
|
+
}
|
|
104
|
+
case 'source': {
|
|
105
|
+
return parse5_utils_1.getAttribute(node, 'src') ? 'src' : 'srcset';
|
|
106
|
+
}
|
|
107
|
+
case 'link': {
|
|
108
|
+
return 'href';
|
|
109
|
+
}
|
|
110
|
+
case 'script': {
|
|
111
|
+
return 'src';
|
|
112
|
+
}
|
|
113
|
+
case 'meta': {
|
|
114
|
+
return 'content';
|
|
115
|
+
}
|
|
116
|
+
default:
|
|
117
|
+
throw new Error(`Unknown node with tagname ${parse5_utils_1.getTagName(node)}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.getSourceAttribute = getSourceAttribute;
|
|
121
|
+
function getSourcePaths(node) {
|
|
122
|
+
const key = getSourceAttribute(node);
|
|
123
|
+
const src = parse5_utils_1.getAttribute(node, key);
|
|
124
|
+
if (typeof key !== 'string' || src === '') {
|
|
125
|
+
throw utils_1.createError(`Missing attribute ${key} in element ${v8_1.serialize(node)}`);
|
|
126
|
+
}
|
|
127
|
+
let paths = [];
|
|
128
|
+
if (src) {
|
|
129
|
+
paths = key !== 'srcset' ? [src] : getSrcSetUrls(src);
|
|
130
|
+
}
|
|
131
|
+
return paths;
|
|
132
|
+
}
|
|
133
|
+
exports.getSourcePaths = getSourcePaths;
|
|
134
|
+
function findAssets(document) {
|
|
135
|
+
return parse5_utils_1.findElements(document, isAsset);
|
|
136
|
+
}
|
|
137
|
+
exports.findAssets = findAssets;
|
|
138
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/assets/utils.ts"],"names":[],"mappings":";;;;;;AACA,gDAAwB;AACxB,oDAA2E;AAC3E,oCAAuC;AACvC,2BAA+B;AAE/B,MAAM,cAAc,GAAG,CAAC,YAAY,CAAC,CAAC;AACtC,MAAM,QAAQ,GAAG,CAAC,GAAG,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE,WAAW,CAAC,CAAC;AAE1F,SAAS,aAAa,CAAC,MAAc;IACnC,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,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QACzC,MAAM,mBAAW,CAAC,qBAAqB,GAAG,eAAe,cAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KAC7E;IAED,IAAI,KAAK,GAAa,EAAE,CAAC;IACzB,IAAI,GAAG,EAAE;QACP,KAAK,GAAG,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;KACvD;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAdD,wCAcC;AAED,SAAgB,UAAU,CAAC,QAAkB;IAC3C,OAAO,2BAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAFD,gCAEC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { rollupPluginHTML, RollupPluginHtml } from './rollupPluginHTML';
|
|
2
|
+
export { InputHTMLOptions, RollupPluginHTMLOptions, GeneratedBundle, EntrypointBundle, TransformHtmlArgs, TransformHtmlFunction, TransformAssetFunction, } from './RollupPluginHTMLOptions';
|
|
3
|
+
export { rollupPluginHTML, RollupPluginHtml };
|
|
4
|
+
export default rollupPluginHTML;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;AAC9C,eAAe,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rollupPluginHTML = void 0;
|
|
4
|
+
const rollupPluginHTML_1 = require("./rollupPluginHTML");
|
|
5
|
+
Object.defineProperty(exports, "rollupPluginHTML", { enumerable: true, get: function () { return rollupPluginHTML_1.rollupPluginHTML; } });
|
|
6
|
+
exports.default = rollupPluginHTML_1.rollupPluginHTML;
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAwE;AAY/D,iGAZA,mCAAgB,OAYA;AACzB,kBAAe,mCAAgB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ScriptModuleTag } from '../RollupPluginHTMLOptions';
|
|
3
|
+
export interface InputAsset {
|
|
4
|
+
filePath: string;
|
|
5
|
+
hashed: boolean;
|
|
6
|
+
content: Buffer;
|
|
7
|
+
}
|
|
8
|
+
export interface InputData {
|
|
9
|
+
html: string;
|
|
10
|
+
name: string;
|
|
11
|
+
moduleImports: ScriptModuleTag[];
|
|
12
|
+
inlineModules: ScriptModuleTag[];
|
|
13
|
+
assets: InputAsset[];
|
|
14
|
+
filePath?: string;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=InputData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InputData.d.ts","sourceRoot":"","sources":["../../src/input/InputData.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,eAAe,EAAE,CAAC;IACjC,aAAa,EAAE,eAAe,EAAE,CAAC;IACjC,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InputData.js","sourceRoot":"","sources":["../../src/input/InputData.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addRollupInput.d.ts","sourceRoot":"","sources":["../../src/input/addRollupInput.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAW7D,wBAAgB,cAAc,CAC5B,YAAY,EAAE,YAAY,EAC1B,cAAc,EAAE,eAAe,EAAE,GAChC,YAAY,CAuCd"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addRollupInput = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
function fromEntries(entries) {
|
|
6
|
+
const obj = {};
|
|
7
|
+
for (const [k, v] of entries) {
|
|
8
|
+
obj[k] = v;
|
|
9
|
+
}
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
function addRollupInput(inputOptions, inputModuleIds) {
|
|
13
|
+
var _a;
|
|
14
|
+
// Add input module ids to existing input option, whether it's a string, array or object
|
|
15
|
+
// this way you can use multiple html plugins all adding their own inputs
|
|
16
|
+
if (!inputOptions.input) {
|
|
17
|
+
return Object.assign(Object.assign({}, inputOptions), { input: inputModuleIds.map(mod => mod.importPath) });
|
|
18
|
+
}
|
|
19
|
+
if (typeof inputOptions.input === 'string') {
|
|
20
|
+
return Object.assign(Object.assign({}, inputOptions), { input: [
|
|
21
|
+
...(((_a = inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.input) === null || _a === void 0 ? void 0 : _a.endsWith('.html')) ? [] : [inputOptions.input]),
|
|
22
|
+
...inputModuleIds.map(mod => mod.importPath),
|
|
23
|
+
] });
|
|
24
|
+
}
|
|
25
|
+
if (Array.isArray(inputOptions.input)) {
|
|
26
|
+
return Object.assign(Object.assign({}, inputOptions), { input: [...inputOptions.input, ...inputModuleIds.map(mod => mod.importPath)] });
|
|
27
|
+
}
|
|
28
|
+
if (typeof inputOptions.input === 'object') {
|
|
29
|
+
return Object.assign(Object.assign({}, inputOptions), { input: Object.assign(Object.assign({}, inputOptions.input), fromEntries(inputModuleIds
|
|
30
|
+
.map(mod => mod.importPath)
|
|
31
|
+
.map(i => [i.split('/').slice(-1)[0].split('.')[0], i]))) });
|
|
32
|
+
}
|
|
33
|
+
throw utils_1.createError(`Unknown rollup input type. Supported inputs are string, array and object.`);
|
|
34
|
+
}
|
|
35
|
+
exports.addRollupInput = addRollupInput;
|
|
36
|
+
//# sourceMappingURL=addRollupInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addRollupInput.js","sourceRoot":"","sources":["../../src/input/addRollupInput.ts"],"names":[],"mappings":";;;AAEA,oCAAuC;AAEvC,SAAS,WAAW,CAAI,OAAsB;IAC5C,MAAM,GAAG,GAAsB,EAAE,CAAC;IAClC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,OAAO,EAAE;QAC5B,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;KACZ;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAgB,cAAc,CAC5B,YAA0B,EAC1B,cAAiC;;IAEjC,wFAAwF;IACxF,yEAAyE;IACzE,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE;QACvB,uCAAY,YAAY,KAAE,KAAK,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAG;KAC9E;IAED,IAAI,OAAO,YAAY,CAAC,KAAK,KAAK,QAAQ,EAAE;QAC1C,uCACK,YAAY,KACf,KAAK,EAAE;gBACL,GAAG,CAAC,OAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,KAAK,0CAAE,QAAQ,CAAC,OAAO,GAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;gBACvE,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC;aAC7C,IACD;KACH;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;QACrC,uCACK,YAAY,KACf,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,KAAK,EAAE,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,IAC5E;KACH;IAED,IAAI,OAAO,YAAY,CAAC,KAAK,KAAK,QAAQ,EAAE;QAC1C,uCACK,YAAY,KACf,KAAK,kCACA,YAAY,CAAC,KAAK,GAClB,WAAW,CACZ,cAAc;iBACX,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC;iBAC1B,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAC1D,KAEH;KACH;IAED,MAAM,mBAAW,CAAC,2EAA2E,CAAC,CAAC;AACjG,CAAC;AA1CD,wCA0CC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Document } from 'parse5';
|
|
2
|
+
import { InputAsset } from '../InputData';
|
|
3
|
+
export interface ExtractAssetsParams {
|
|
4
|
+
document: Document;
|
|
5
|
+
htmlFilePath: string;
|
|
6
|
+
htmlDir: string;
|
|
7
|
+
rootDir: string;
|
|
8
|
+
absolutePathPrefix?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function extractAssets(params: ExtractAssetsParams): InputAsset[];
|
|
11
|
+
//# sourceMappingURL=extractAssets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractAssets.d.ts","sourceRoot":"","sources":["../../../src/input/extract/extractAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAa,MAAM,QAAQ,CAAC;AAG7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAQ1C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,UAAU,EAAE,CAiCvE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extractAssets = void 0;
|
|
7
|
+
const parse5_1 = require("parse5");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const utils_1 = require("../../assets/utils");
|
|
11
|
+
function extractAssets(params) {
|
|
12
|
+
const assetNodes = utils_1.findAssets(params.document);
|
|
13
|
+
const allAssets = [];
|
|
14
|
+
for (const node of assetNodes) {
|
|
15
|
+
const sourcePaths = utils_1.getSourcePaths(node);
|
|
16
|
+
for (const sourcePath of sourcePaths) {
|
|
17
|
+
const filePath = utils_1.resolveAssetFilePath(sourcePath, params.htmlDir, params.rootDir, params.absolutePathPrefix);
|
|
18
|
+
const hashed = utils_1.isHashedAsset(node);
|
|
19
|
+
const alreadyHandled = allAssets.find(a => a.filePath === filePath && a.hashed === hashed);
|
|
20
|
+
if (!alreadyHandled) {
|
|
21
|
+
try {
|
|
22
|
+
fs_1.default.accessSync(filePath);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
const elStr = parse5_1.serialize(node);
|
|
26
|
+
const htmlPath = path_1.default.relative(process.cwd(), params.htmlFilePath);
|
|
27
|
+
throw new Error(`Could not find ${filePath} referenced from HTML file ${htmlPath} from element ${elStr}.`);
|
|
28
|
+
}
|
|
29
|
+
const content = fs_1.default.readFileSync(filePath);
|
|
30
|
+
allAssets.push({ filePath, hashed, content });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return allAssets;
|
|
35
|
+
}
|
|
36
|
+
exports.extractAssets = extractAssets;
|
|
37
|
+
//# sourceMappingURL=extractAssets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractAssets.js","sourceRoot":"","sources":["../../../src/input/extract/extractAssets.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA6C;AAC7C,4CAAoB;AACpB,gDAAwB;AAExB,8CAK4B;AAU5B,SAAgB,aAAa,CAAC,MAA2B;IACvD,MAAM,UAAU,GAAG,kBAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/C,MAAM,SAAS,GAAiB,EAAE,CAAC;IAEnC,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE;QAC7B,MAAM,WAAW,GAAG,sBAAc,CAAC,IAAI,CAAC,CAAC;QACzC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;YACpC,MAAM,QAAQ,GAAG,4BAAoB,CACnC,UAAU,EACV,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,kBAAkB,CAC1B,CAAC;YACF,MAAM,MAAM,GAAG,qBAAa,CAAC,IAAI,CAAC,CAAC;YACnC,MAAM,cAAc,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC;YAC3F,IAAI,CAAC,cAAc,EAAE;gBACnB,IAAI;oBACF,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;iBACzB;gBAAC,OAAO,KAAK,EAAE;oBACd,MAAM,KAAK,GAAG,kBAAS,CAAC,IAAI,CAAC,CAAC;oBAC9B,MAAM,QAAQ,GAAG,cAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;oBACnE,MAAM,IAAI,KAAK,CACb,kBAAkB,QAAQ,8BAA8B,QAAQ,iBAAiB,KAAK,GAAG,CAC1F,CAAC;iBACH;gBAED,MAAM,OAAO,GAAG,YAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;gBAC1C,SAAS,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;aAC/C;SACF;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAjCD,sCAiCC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Document } from 'parse5';
|
|
2
|
+
import { ScriptModuleTag } from '../../RollupPluginHTMLOptions';
|
|
3
|
+
export interface ExtractModulesParams {
|
|
4
|
+
document: Document;
|
|
5
|
+
htmlDir: string;
|
|
6
|
+
rootDir: string;
|
|
7
|
+
absolutePathPrefix?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function extractModules(params: ExtractModulesParams): {
|
|
10
|
+
moduleImports: ScriptModuleTag[];
|
|
11
|
+
inlineModules: ScriptModuleTag[];
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=extractModules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractModules.d.ts","sourceRoot":"","sources":["../../../src/input/extract/extractModules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAa,MAAM,QAAQ,CAAC;AAK7C,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAeD,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB;;;EAiD1D"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extractModules = void 0;
|
|
7
|
+
const parse5_utils_1 = require("@web/parse5-utils");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
+
const utils_1 = require("../../assets/utils");
|
|
11
|
+
const parse5_utils_2 = require("@web/parse5-utils");
|
|
12
|
+
function createContentHash(content) {
|
|
13
|
+
return crypto_1.default.createHash('md5').update(content).digest('hex');
|
|
14
|
+
}
|
|
15
|
+
function isAbsolute(src) {
|
|
16
|
+
try {
|
|
17
|
+
new URL(src);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
catch (_a) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function extractModules(params) {
|
|
25
|
+
const { document, htmlDir, rootDir, absolutePathPrefix } = params;
|
|
26
|
+
const scriptNodes = parse5_utils_1.findElements(document, e => parse5_utils_1.getTagName(e) === 'script' && parse5_utils_1.getAttribute(e, 'type') === 'module');
|
|
27
|
+
const moduleImports = [];
|
|
28
|
+
const inlineModules = [];
|
|
29
|
+
for (const scriptNode of scriptNodes) {
|
|
30
|
+
const src = parse5_utils_1.getAttribute(scriptNode, 'src');
|
|
31
|
+
const allAttributes = parse5_utils_2.getAttributes(scriptNode);
|
|
32
|
+
const attributes = [];
|
|
33
|
+
for (const attributeName of Object.keys(allAttributes)) {
|
|
34
|
+
if (attributeName !== 'src' && attributeName !== 'type') {
|
|
35
|
+
attributes.push({ name: attributeName, value: allAttributes[attributeName] });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!src) {
|
|
39
|
+
// turn inline module (<script type="module"> ...code ... </script>)
|
|
40
|
+
const code = parse5_utils_1.getTextContent(scriptNode);
|
|
41
|
+
// inline modules should be relative to the HTML file to resolve relative imports
|
|
42
|
+
// we make it unique with a content hash, so that duplicate modules are deduplicated
|
|
43
|
+
const importPath = path_1.default.posix.join(htmlDir, `/inline-module-${createContentHash(code)}.js`);
|
|
44
|
+
if (!inlineModules.find(tag => tag.importPath === importPath)) {
|
|
45
|
+
inlineModules.push({
|
|
46
|
+
importPath,
|
|
47
|
+
attributes,
|
|
48
|
+
code,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
parse5_utils_1.remove(scriptNode);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
if (!isAbsolute(src)) {
|
|
55
|
+
// external script <script type="module" src="./foo.js"></script>
|
|
56
|
+
const importPath = utils_1.resolveAssetFilePath(src, htmlDir, rootDir, absolutePathPrefix);
|
|
57
|
+
moduleImports.push({
|
|
58
|
+
importPath,
|
|
59
|
+
attributes,
|
|
60
|
+
});
|
|
61
|
+
parse5_utils_1.remove(scriptNode);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { moduleImports, inlineModules };
|
|
66
|
+
}
|
|
67
|
+
exports.extractModules = extractModules;
|
|
68
|
+
//# sourceMappingURL=extractModules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractModules.js","sourceRoot":"","sources":["../../../src/input/extract/extractModules.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAmG;AAEnG,gDAAwB;AACxB,oDAA4B;AAC5B,8CAA0D;AAC1D,oDAAkD;AAUlD,SAAS,iBAAiB,CAAC,OAAe;IACxC,OAAO,gBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,UAAU,CAAC,GAAW;IAC7B,IAAI;QACF,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,IAAI,CAAC;KACb;IAAC,WAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAED,SAAgB,cAAc,CAAC,MAA4B;IACzD,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAAC;IAClE,MAAM,WAAW,GAAG,2BAAY,CAC9B,QAAQ,EACR,CAAC,CAAC,EAAE,CAAC,yBAAU,CAAC,CAAC,CAAC,KAAK,QAAQ,IAAI,2BAAY,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,QAAQ,CACxE,CAAC;IAEF,MAAM,aAAa,GAAsB,EAAE,CAAC;IAC5C,MAAM,aAAa,GAAsB,EAAE,CAAC;IAE5C,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,MAAM,GAAG,GAAG,2BAAY,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAE5C,MAAM,aAAa,GAAG,4BAAa,CAAC,UAAU,CAAC,CAAC;QAChD,MAAM,UAAU,GAAgB,EAAE,CAAC;QACnC,KAAK,MAAM,aAAa,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE;YACtD,IAAI,aAAa,KAAK,KAAK,IAAI,aAAa,KAAK,MAAM,EAAE;gBACvD,UAAU,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;aAC/E;SACF;QAED,IAAI,CAAC,GAAG,EAAE;YACR,oEAAoE;YACpE,MAAM,IAAI,GAAG,6BAAc,CAAC,UAAU,CAAC,CAAC;YACxC,iFAAiF;YACjF,oFAAoF;YACpF,MAAM,UAAU,GAAG,cAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,kBAAkB,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC5F,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,KAAK,UAAU,CAAC,EAAE;gBAC7D,aAAa,CAAC,IAAI,CAAC;oBACjB,UAAU;oBACV,UAAU;oBACV,IAAI;iBACL,CAAC,CAAC;aACJ;YACD,qBAAM,CAAC,UAAU,CAAC,CAAC;SACpB;aAAM;YACL,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;gBACpB,iEAAiE;gBACjE,MAAM,UAAU,GAAG,4BAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC;gBACnF,aAAa,CAAC,IAAI,CAAC;oBACjB,UAAU;oBACV,UAAU;iBACX,CAAC,CAAC;gBACH,qBAAM,CAAC,UAAU,CAAC,CAAC;aACpB;SACF;KACF;IAED,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC;AAC1C,CAAC;AAjDD,wCAiDC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ExtractParams {
|
|
2
|
+
html: string;
|
|
3
|
+
htmlFilePath: string;
|
|
4
|
+
rootDir: string;
|
|
5
|
+
extractAssets: boolean;
|
|
6
|
+
absolutePathPrefix?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function extractModulesAndAssets(params: ExtractParams): {
|
|
9
|
+
moduleImports: import("../../RollupPluginHTMLOptions").ScriptModuleTag[];
|
|
10
|
+
inlineModules: import("../../RollupPluginHTMLOptions").ScriptModuleTag[];
|
|
11
|
+
assets: import("../InputData").InputAsset[];
|
|
12
|
+
htmlWithoutModules: string;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=extractModulesAndAssets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractModulesAndAssets.d.ts","sourceRoot":"","sources":["../../../src/input/extract/extractModulesAndAssets.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,aAAa;;;;;EAoB5D"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.extractModulesAndAssets = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const parse5_1 = require("parse5");
|
|
9
|
+
const extractModules_1 = require("./extractModules");
|
|
10
|
+
const extractAssets_1 = require("./extractAssets");
|
|
11
|
+
function extractModulesAndAssets(params) {
|
|
12
|
+
const { html, htmlFilePath, rootDir, absolutePathPrefix } = params;
|
|
13
|
+
const htmlDir = path_1.default.dirname(htmlFilePath);
|
|
14
|
+
const document = parse5_1.parse(html);
|
|
15
|
+
// extract functions mutate the AST
|
|
16
|
+
const { moduleImports, inlineModules } = extractModules_1.extractModules({
|
|
17
|
+
document,
|
|
18
|
+
htmlDir,
|
|
19
|
+
rootDir,
|
|
20
|
+
absolutePathPrefix,
|
|
21
|
+
});
|
|
22
|
+
const assets = params.extractAssets
|
|
23
|
+
? extractAssets_1.extractAssets({ document, htmlDir, htmlFilePath, rootDir, absolutePathPrefix })
|
|
24
|
+
: [];
|
|
25
|
+
// turn mutated AST back to a string
|
|
26
|
+
const updatedHtmlString = parse5_1.serialize(document);
|
|
27
|
+
return { moduleImports, inlineModules, assets, htmlWithoutModules: updatedHtmlString };
|
|
28
|
+
}
|
|
29
|
+
exports.extractModulesAndAssets = extractModulesAndAssets;
|
|
30
|
+
//# sourceMappingURL=extractModulesAndAssets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractModulesAndAssets.js","sourceRoot":"","sources":["../../../src/input/extract/extractModulesAndAssets.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,mCAA0C;AAC1C,qDAAkD;AAClD,mDAAgD;AAUhD,SAAgB,uBAAuB,CAAC,MAAqB;IAC3D,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAAC;IACnE,MAAM,OAAO,GAAG,cAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,cAAK,CAAC,IAAI,CAAC,CAAC;IAE7B,mCAAmC;IACnC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,+BAAc,CAAC;QACtD,QAAQ;QACR,OAAO;QACP,OAAO;QACP,kBAAkB;KACnB,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,MAAM,CAAC,aAAa;QACjC,CAAC,CAAC,6BAAa,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC;QACjF,CAAC,CAAC,EAAE,CAAC;IAEP,oCAAoC;IACpC,MAAM,iBAAiB,GAAG,kBAAS,CAAC,QAAQ,CAAC,CAAC;IAE9C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;AACzF,CAAC;AApBD,0DAoBC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RollupPluginHTMLOptions } from '../RollupPluginHTMLOptions';
|
|
2
|
+
import { InputData } from './InputData';
|
|
3
|
+
import { InputOption } from 'rollup';
|
|
4
|
+
export interface CreateInputDataParams {
|
|
5
|
+
name: string;
|
|
6
|
+
html: string;
|
|
7
|
+
rootDir: string;
|
|
8
|
+
filePath?: string;
|
|
9
|
+
extractAssets: boolean;
|
|
10
|
+
absolutePathPrefix?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function getInputData(pluginOptions: RollupPluginHTMLOptions, rollupInput?: InputOption): InputData[];
|
|
13
|
+
//# sourceMappingURL=getInputData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getInputData.d.ts","sourceRoot":"","sources":["../../src/input/getInputData.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAkBrC,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAuBD,wBAAgB,YAAY,CAC1B,aAAa,EAAE,uBAAuB,EACtC,WAAW,CAAC,EAAE,WAAW,GACxB,SAAS,EAAE,CA2Db"}
|