@rollup-extras/plugin-html 1.3.3 → 1.4.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 +1 -1
- package/README.md +40 -14
- package/asset-factories/package.json +5 -0
- package/dist/asset-factories.cjs +61 -0
- package/dist/asset-factories.d.ts +6 -0
- package/dist/asset-factories.mjs +56 -0
- package/dist/index.cjs +269 -285
- package/dist/index.d.ts +7 -7
- package/dist/index.mjs +269 -285
- package/dist/shared.cjs +31 -0
- package/dist/shared.d.ts +5 -0
- package/dist/shared.mjs +26 -0
- package/dist/types.d.ts +37 -34
- package/package.json +20 -29
package/dist/index.cjs
CHANGED
|
@@ -6,292 +6,276 @@ var path = require('path');
|
|
|
6
6
|
var options = require('@rollup-extras/utils/options');
|
|
7
7
|
var logger = require('@rollup-extras/utils/logger');
|
|
8
8
|
var mutliConfigPluginBase = require('@rollup-extras/utils/mutli-config-plugin-base');
|
|
9
|
+
var shared = require('./shared.cjs');
|
|
9
10
|
|
|
10
|
-
const defaultTemplate = '<!DOCTYPE html><html><head></head><body></body></html>';
|
|
11
|
-
const headClosingElement = '</head>';
|
|
12
|
-
const bodyClosingElement = '</body>';
|
|
13
|
-
const cssExtention = '.css';
|
|
14
|
-
const defaults = {
|
|
15
|
-
pluginName: '@rollup-extras/plugin-html',
|
|
16
|
-
outputFile: 'index.html',
|
|
17
|
-
watch: true,
|
|
18
|
-
useWriteBundle: false,
|
|
19
|
-
emitFile: 'auto',
|
|
20
|
-
injectIntoHead: (fileName) => fileName.endsWith(cssExtention),
|
|
21
|
-
ignore: toAssetPredicate(false),
|
|
22
|
-
templateFactory: ((template, assets, defaultTemplateFactory) => defaultTemplateFactory(template, assets))
|
|
23
|
-
};
|
|
24
|
-
const factories = { logger, injectIntoHead: predicateFactory, ignore: predicateFactory };
|
|
25
|
-
function index (options$1 = {}) {
|
|
26
|
-
const { pluginName, outputFile, template, watch, emitFile, conditionalLoading, logger, useWriteBundle, logLevel, useEmittedTemplate, injectIntoHead, ignore, assetsFactory, templateFactory } = options.getOptionsObject(options$1,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return
|
|
278
|
-
}
|
|
279
|
-
function defaultTemplateFactory(template, assets) {
|
|
280
|
-
const assetsAsArray = assets.asset
|
|
281
|
-
.concat((assets.iife.length ? assets.iife : assets.umd))
|
|
282
|
-
.concat(assets.es)
|
|
283
|
-
.map((asset) => {
|
|
284
|
-
if (typeof asset.html === 'function') {
|
|
285
|
-
asset.html = asset.html(assets);
|
|
286
|
-
}
|
|
287
|
-
return asset;
|
|
288
|
-
});
|
|
289
|
-
const headElements = assetsAsArray.filter(asset => asset.head).map(asset => asset.html);
|
|
290
|
-
const bodyElements = assetsAsArray.filter(asset => !asset.head).map(asset => asset.html);
|
|
291
|
-
const headIndex = template.toLowerCase().indexOf(headClosingElement);
|
|
292
|
-
template = `${template.substring(0, headIndex)}${headElements.join('')}${template.substring(headIndex)}`;
|
|
293
|
-
const bodyIndex = template.toLowerCase().indexOf(bodyClosingElement);
|
|
294
|
-
return `${template.substring(0, bodyIndex)}${bodyElements.join('')}${template.substring(bodyIndex)}`;
|
|
11
|
+
const defaultTemplate = '<!DOCTYPE html><html><head></head><body></body></html>';
|
|
12
|
+
const headClosingElement = '</head>';
|
|
13
|
+
const bodyClosingElement = '</body>';
|
|
14
|
+
const cssExtention = '.css';
|
|
15
|
+
const defaults = {
|
|
16
|
+
pluginName: '@rollup-extras/plugin-html',
|
|
17
|
+
outputFile: 'index.html',
|
|
18
|
+
watch: true,
|
|
19
|
+
useWriteBundle: false,
|
|
20
|
+
emitFile: 'auto',
|
|
21
|
+
injectIntoHead: (fileName) => fileName.endsWith(cssExtention),
|
|
22
|
+
ignore: shared.toAssetPredicate(false),
|
|
23
|
+
templateFactory: ((template, assets, defaultTemplateFactory) => defaultTemplateFactory(template, assets))
|
|
24
|
+
};
|
|
25
|
+
const factories = { logger, injectIntoHead: predicateFactory, ignore: predicateFactory };
|
|
26
|
+
function index (options$1 = {}) {
|
|
27
|
+
const { pluginName, outputFile, template, watch, emitFile, conditionalLoading, logger, useWriteBundle, logLevel, useEmittedTemplate, injectIntoHead, ignore, assetsFactory, templateFactory } = options.getOptionsObject(options$1, {
|
|
28
|
+
...defaults,
|
|
29
|
+
useEmittedTemplate: !('template' in options$1),
|
|
30
|
+
logLevel: options$1.verbose ? 1 /* LogLevel.info */ : 0 /* LogLevel.verbose */
|
|
31
|
+
}, factories), hasCustomTemplateFactory = 'templateFactory' in options$1;
|
|
32
|
+
let templateString = defaultTemplate, hasTemplateFile = false;
|
|
33
|
+
if (template) {
|
|
34
|
+
if (isUsableByDefaultTemplateFactory(template)) {
|
|
35
|
+
templateString = template;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (watch) {
|
|
39
|
+
try {
|
|
40
|
+
// using sync fs call because we need to return plugin object immidiately
|
|
41
|
+
useNewTemplate(oldStyleFs.readFileSync(template, { encoding: 'utf8' }));
|
|
42
|
+
hasTemplateFile = true;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
handleTemplateReadError(e);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
templateString = new Promise(resolve => {
|
|
50
|
+
fs.readFile(template, { encoding: 'utf8' })
|
|
51
|
+
.then((newTemplateString) => {
|
|
52
|
+
if (!isUsableByDefaultTemplateFactory(newTemplateString) && !hasCustomTemplateFactory) {
|
|
53
|
+
warnAboutUsingDefaultTemplate();
|
|
54
|
+
resolve(defaultTemplate);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
resolve(newTemplateString);
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
.catch(handleTemplateReadError);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
let initialDir = '', fileNameInInitialDir, assets = freshAssets();
|
|
66
|
+
const processedFiles = new Set();
|
|
67
|
+
const instance = mutliConfigPluginBase.multiConfigPluginBase(useWriteBundle, pluginName, generateBundle, updateAssets);
|
|
68
|
+
const baseRenderStart = instance.renderStart;
|
|
69
|
+
const baseAddInstance = instance.api.addInstance;
|
|
70
|
+
instance.renderStart = function (outputOptions, inputOptions) {
|
|
71
|
+
logger('started collecting information', 0 /* LogLevel.verbose */);
|
|
72
|
+
initialDir = outputOptions.dir || '';
|
|
73
|
+
fileNameInInitialDir = path.join(initialDir, outputFile);
|
|
74
|
+
return baseRenderStart.call(this, outputOptions, inputOptions);
|
|
75
|
+
};
|
|
76
|
+
instance.api.addInstance = () => {
|
|
77
|
+
const instance = baseAddInstance();
|
|
78
|
+
if (hasTemplateFile && watch) {
|
|
79
|
+
instance.buildStart = buildStart;
|
|
80
|
+
}
|
|
81
|
+
return instance;
|
|
82
|
+
};
|
|
83
|
+
if (hasTemplateFile && watch) {
|
|
84
|
+
instance.buildStart = async function () {
|
|
85
|
+
try {
|
|
86
|
+
useNewTemplate(await fs.readFile(template, { encoding: 'utf8' }));
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
handleTemplateReadError(e);
|
|
90
|
+
}
|
|
91
|
+
await buildStart.apply(this);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return instance;
|
|
95
|
+
async function updateAssets(options, bundle, remainingConfigsCount, remainingOutputsCount) {
|
|
96
|
+
await getAssets(options, bundle);
|
|
97
|
+
const statistics = Object.keys(assets)
|
|
98
|
+
.map(key => ({ key, count: assets[key].length }))
|
|
99
|
+
.filter(item => item.count)
|
|
100
|
+
.map(({ key, count }) => `${key}: ${count}`)
|
|
101
|
+
.join(', ');
|
|
102
|
+
logger(`assets collected: [${statistics}], remaining: ${remainingOutputsCount} outputs, ${remainingConfigsCount} configs`, 0 /* LogLevel.verbose */);
|
|
103
|
+
const dir = options.dir || '', fileName = path.relative(dir, fileNameInInitialDir);
|
|
104
|
+
if (fileName in bundle) {
|
|
105
|
+
if (useEmittedTemplate) {
|
|
106
|
+
logger(`using exiting emitted ${fileName} as an input for out templateFactory`, 0 /* LogLevel.verbose */);
|
|
107
|
+
const source = bundle[fileName].type === 'asset' ? bundle[fileName].source.toString() : bundle[fileName].code;
|
|
108
|
+
useNewTemplate(source);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
logger(`removing exiting emitted ${fileName}`, 0 /* LogLevel.verbose */);
|
|
112
|
+
}
|
|
113
|
+
if (remainingConfigsCount === 0 && emitFile && !useWriteBundle) {
|
|
114
|
+
delete bundle[fileName];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function freshAssets() {
|
|
119
|
+
return {
|
|
120
|
+
asset: [],
|
|
121
|
+
es: [],
|
|
122
|
+
iife: [],
|
|
123
|
+
umd: []
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function useNewTemplate(newTemplateString) {
|
|
127
|
+
if (!isUsableByDefaultTemplateFactory(newTemplateString) && !hasCustomTemplateFactory) {
|
|
128
|
+
warnAboutUsingDefaultTemplate();
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
templateString = newTemplateString;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function handleTemplateReadError(e) {
|
|
135
|
+
if (e?.code === 'ENOENT') {
|
|
136
|
+
logger('template nor a file or string', 2 /* LogLevel.warn */, e);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
logger('error reading template', 2 /* LogLevel.warn */, e);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function warnAboutUsingDefaultTemplate() {
|
|
143
|
+
logger('template is unusable by default template factory, using default one', 2 /* LogLevel.warn */);
|
|
144
|
+
}
|
|
145
|
+
async function buildStart() {
|
|
146
|
+
this.addWatchFile(template);
|
|
147
|
+
}
|
|
148
|
+
async function generateBundle(options) {
|
|
149
|
+
logger.start('generating html', logLevel);
|
|
150
|
+
try {
|
|
151
|
+
const dir = options.dir || '', fileName = path.relative(dir, fileNameInInitialDir);
|
|
152
|
+
const depromisifiedTemplateString = await templateString, source = await templateFactory(depromisifiedTemplateString, assets, defaultTemplateFactory);
|
|
153
|
+
if (!emitFile || fileName.startsWith('..') || useWriteBundle) {
|
|
154
|
+
if (emitFile && emitFile !== 'auto') {
|
|
155
|
+
logger('cannot emitFile because it is outside of current output.dir, using writeFile instead', 0 /* LogLevel.verbose */);
|
|
156
|
+
}
|
|
157
|
+
await fs.mkdir(path.dirname(fileNameInInitialDir), { recursive: true });
|
|
158
|
+
await fs.writeFile(fileNameInInitialDir, source);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
this.emitFile({
|
|
162
|
+
type: 'asset',
|
|
163
|
+
fileName,
|
|
164
|
+
source
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
// reset assets and configs for the next iteration
|
|
168
|
+
assets = freshAssets();
|
|
169
|
+
processedFiles.clear();
|
|
170
|
+
logger.finish('html file generated');
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
logger.finish('html generation failed', 3 /* LogLevel.error */, e);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async function getAssets(options, bundle) {
|
|
177
|
+
const dir = options.dir || '';
|
|
178
|
+
for (const fileName of Object.keys(bundle)) {
|
|
179
|
+
const relativeToRootAssetPath = path.join(dir, fileName);
|
|
180
|
+
if (ignore(relativeToRootAssetPath) || processedFiles.has(relativeToRootAssetPath)) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
processedFiles.add(relativeToRootAssetPath);
|
|
184
|
+
if (bundle[fileName].type === 'asset') {
|
|
185
|
+
if (await useAssetFactory(fileName, relativeToRootAssetPath, bundle[fileName].source, 'asset')) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (fileName.endsWith(cssExtention)) {
|
|
189
|
+
const assetPath = path.relative(initialDir, relativeToRootAssetPath);
|
|
190
|
+
assets.asset.push({
|
|
191
|
+
html: shared.getLinkElement(assetPath),
|
|
192
|
+
head: injectIntoHead(relativeToRootAssetPath),
|
|
193
|
+
type: 'asset'
|
|
194
|
+
});
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (bundle[fileName].type === 'chunk') {
|
|
199
|
+
const chunk = bundle[fileName];
|
|
200
|
+
if (chunk.isEntry) {
|
|
201
|
+
if (await useAssetFactory(fileName, relativeToRootAssetPath, chunk.code, options.format)) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (options.format === 'es' || options.format === 'iife' || options.format === 'umd') {
|
|
205
|
+
const assetPath = path.relative(initialDir, relativeToRootAssetPath);
|
|
206
|
+
assets[options.format].push({
|
|
207
|
+
html: (assets) => {
|
|
208
|
+
let useConditionalLoading = conditionalLoading;
|
|
209
|
+
useConditionalLoading ??= !!((assets.iife.length
|
|
210
|
+
|| assets.umd.length)
|
|
211
|
+
&& assets.es.length);
|
|
212
|
+
return (options.format === 'iife' || options.format === 'umd') ? shared.getNonModuleScriptElement(assetPath, !!useConditionalLoading) : shared.getModuleScriptElement(assetPath);
|
|
213
|
+
},
|
|
214
|
+
head: injectIntoHead(relativeToRootAssetPath),
|
|
215
|
+
type: 'asset'
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async function useAssetFactory(fileName, relativeToRootAssetPath, source, format) {
|
|
223
|
+
if (assetsFactory) {
|
|
224
|
+
try {
|
|
225
|
+
let asset = await assetsFactory(fileName, source, format);
|
|
226
|
+
if (asset) {
|
|
227
|
+
if (typeof asset === 'string') {
|
|
228
|
+
asset = {
|
|
229
|
+
html: asset,
|
|
230
|
+
head: injectIntoHead(relativeToRootAssetPath),
|
|
231
|
+
type: format
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
if (!assets[asset.type]) {
|
|
235
|
+
assets[asset.type] = [];
|
|
236
|
+
}
|
|
237
|
+
assets[asset.type].push(asset);
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (e) {
|
|
242
|
+
logger('exception in assetFactory', 2 /* LogLevel.warn */, e);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function isUsableByDefaultTemplateFactory(template) {
|
|
249
|
+
return template.indexOf(headClosingElement) >= 0 && template.indexOf(bodyClosingElement) >= 0;
|
|
250
|
+
}
|
|
251
|
+
function predicateFactory(options, field) {
|
|
252
|
+
if (options[field] != null) {
|
|
253
|
+
const predicate = shared.toAssetPredicate(options[field]);
|
|
254
|
+
if (predicate) {
|
|
255
|
+
return predicate;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
options.logger && options.logger(`${field} option ignored because it is not a function, RegExp, string or boolean`, 2 /* LogLevel.warn */);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return defaults[field];
|
|
262
|
+
}
|
|
263
|
+
function defaultTemplateFactory(template, assets) {
|
|
264
|
+
const assetsAsArray = assets.asset
|
|
265
|
+
.concat((assets.iife.length ? assets.iife : assets.umd))
|
|
266
|
+
.concat(assets.es)
|
|
267
|
+
.map((asset) => {
|
|
268
|
+
if (typeof asset.html === 'function') {
|
|
269
|
+
asset.html = asset.html(assets);
|
|
270
|
+
}
|
|
271
|
+
return asset;
|
|
272
|
+
});
|
|
273
|
+
const headElements = assetsAsArray.filter(asset => asset.head).map(asset => asset.html);
|
|
274
|
+
const bodyElements = assetsAsArray.filter(asset => !asset.head).map(asset => asset.html);
|
|
275
|
+
const headIndex = template.toLowerCase().indexOf(headClosingElement);
|
|
276
|
+
template = `${template.substring(0, headIndex)}${headElements.join('')}${template.substring(headIndex)}`;
|
|
277
|
+
const bodyIndex = template.toLowerCase().indexOf(bodyClosingElement);
|
|
278
|
+
return `${template.substring(0, bodyIndex)}${bodyElements.join('')}${template.substring(bodyIndex)}`;
|
|
295
279
|
}
|
|
296
280
|
|
|
297
281
|
module.exports = index;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Plugin } from 'rollup';
|
|
2
|
-
import { HtmlPluginOptions } from './types';
|
|
3
|
-
export default function (options?: HtmlPluginOptions): Plugin & {
|
|
4
|
-
api: {
|
|
5
|
-
addInstance(): Plugin;
|
|
6
|
-
};
|
|
7
|
-
};
|
|
1
|
+
import type { Plugin } from 'rollup';
|
|
2
|
+
import type { HtmlPluginOptions } from './types';
|
|
3
|
+
export default function (options?: HtmlPluginOptions): Plugin & {
|
|
4
|
+
api: {
|
|
5
|
+
addInstance(): Plugin;
|
|
6
|
+
};
|
|
7
|
+
};
|