@rollup-extras/plugin-html 1.4.0 → 1.4.2
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 +10 -10
- package/dist/index.cjs +7 -8
- package/dist/index.mjs +7 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,11 +6,11 @@ Points:
|
|
|
6
6
|
|
|
7
7
|
- Inject file names with hashes
|
|
8
8
|
- Watch on a template file and trigger rebuild if it is changed
|
|
9
|
-
- Provides minimalistic template by default, so you are ready to start without configuration
|
|
9
|
+
- Provides a minimalistic template by default, so you are ready to start without configuration
|
|
10
10
|
- Supports multiple rollup configs (will trigger only when last output generated)
|
|
11
|
-
- Extensible through API so you can plug in something for
|
|
11
|
+
- Extensible through API so you can plug in something for HTML processing or generate new types of HTML elements
|
|
12
12
|
|
|
13
|
-
Uses [`@niceties/logger`](https://github.com/kshutkin/niceties/blob/main/logger/README.md) to log messages, can be configured through `@niceties/logger` API.
|
|
13
|
+
Uses [`@niceties/logger`](https://github.com/kshutkin/niceties/blob/main/logger/README.md) to log messages, which can be configured through `@niceties/logger` API.
|
|
14
14
|
|
|
15
15
|
[Changelog](./CHANGELOG.md)
|
|
16
16
|
|
|
@@ -40,13 +40,13 @@ export default {
|
|
|
40
40
|
|
|
41
41
|
## Providing options
|
|
42
42
|
|
|
43
|
-
Just pass options to the plugin function.
|
|
43
|
+
Just pass options to the plugin function. The returned object is the plugin instance which can be passed to rollup.
|
|
44
44
|
|
|
45
45
|
```javascript
|
|
46
46
|
html({option: value, option2: value2})
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
For additional plugin instances (in case of multiple configs) please use
|
|
49
|
+
For additional plugin instances (in case of multiple configs) please use `firstInstance.api.addInstance()`
|
|
50
50
|
|
|
51
51
|
## Options
|
|
52
52
|
|
|
@@ -60,7 +60,7 @@ For debugging purposes, so many instances of a plugin can be differentiated in d
|
|
|
60
60
|
|
|
61
61
|
Optional, string, default: `'index.html'`.
|
|
62
62
|
|
|
63
|
-
Used to override output file name. If a filename with the same name exists in the pipeline it will be removed or overwritten in the process but its content by default will be used as
|
|
63
|
+
Used to override output file name. If a filename with the same name exists in the pipeline it will be removed or overwritten in the process but its content by default will be used as input for this plugin. In the following example file emitted by copy plugin will be used as input for this plugin:
|
|
64
64
|
|
|
65
65
|
```javascript
|
|
66
66
|
import copy from '@rollup-extras/plugin-copy';
|
|
@@ -94,19 +94,19 @@ If the plugin found a template file name this option defines if the plugin needs
|
|
|
94
94
|
|
|
95
95
|
Optional, boolean, default: true.
|
|
96
96
|
|
|
97
|
-
Defines if the plugin should use this.emitFile or should just write it to disk.
|
|
97
|
+
Defines if the plugin should use this.emitFile or should just write it to disk. The option can be ignored in setup with multiple rollup configs.
|
|
98
98
|
|
|
99
99
|
### useEmittedTemplate
|
|
100
100
|
|
|
101
101
|
Optional, boolean, default: true.
|
|
102
102
|
|
|
103
|
-
Defines what the plugin does if it finds a file with the expected file name in the bundle. By default it will be used as a template. Templates provided through the template option should be of higher priority to the plugin.
|
|
103
|
+
Defines what the plugin does if it finds a file with the expected file name in the bundle. By default, it will be used as a template. Templates provided through the template option should be of higher priority to the plugin.
|
|
104
104
|
|
|
105
105
|
### conditionalLoading
|
|
106
106
|
|
|
107
107
|
Optional, boolean, default: undefined.
|
|
108
108
|
|
|
109
|
-
Defines if plugin adds `nomodule`
|
|
109
|
+
Defines if the plugin adds `nomodule` attributes for non-modular js chunks. By default, it is done only if we have an `es` output in one of the bundles processed by the plugin. Also plugin values `iife` outputs higher than `umd` and if we have both filters out `umd` ones. This can be changed only by providing a custom `assetFactory`.
|
|
110
110
|
|
|
111
111
|
### injectIntoHead
|
|
112
112
|
|
|
@@ -216,7 +216,7 @@ Creates a simple module script element.
|
|
|
216
216
|
|
|
217
217
|
`(...factories: AssetFactory[]) => AssetFactory`
|
|
218
218
|
|
|
219
|
-
Combines several factories, calls them in order, the first factory
|
|
219
|
+
Combines several factories, and calls them in order, the first factory-created asset wins.
|
|
220
220
|
|
|
221
221
|
## Configuration
|
|
222
222
|
|
package/dist/index.cjs
CHANGED
|
@@ -69,7 +69,7 @@ function index (options$1 = {}) {
|
|
|
69
69
|
const baseAddInstance = instance.api.addInstance;
|
|
70
70
|
instance.renderStart = function (outputOptions, inputOptions) {
|
|
71
71
|
logger('started collecting information', 0 /* LogLevel.verbose */);
|
|
72
|
-
initialDir = outputOptions.dir
|
|
72
|
+
initialDir = outputOptions.dir ?? '';
|
|
73
73
|
fileNameInInitialDir = path.join(initialDir, outputFile);
|
|
74
74
|
return baseRenderStart.call(this, outputOptions, inputOptions);
|
|
75
75
|
};
|
|
@@ -100,7 +100,7 @@ function index (options$1 = {}) {
|
|
|
100
100
|
.map(({ key, count }) => `${key}: ${count}`)
|
|
101
101
|
.join(', ');
|
|
102
102
|
logger(`assets collected: [${statistics}], remaining: ${remainingOutputsCount} outputs, ${remainingConfigsCount} configs`, 0 /* LogLevel.verbose */);
|
|
103
|
-
const dir = options.dir
|
|
103
|
+
const dir = options.dir ?? '', fileName = path.relative(dir, fileNameInInitialDir);
|
|
104
104
|
if (fileName in bundle) {
|
|
105
105
|
if (useEmittedTemplate) {
|
|
106
106
|
logger(`using exiting emitted ${fileName} as an input for out templateFactory`, 0 /* LogLevel.verbose */);
|
|
@@ -148,7 +148,7 @@ function index (options$1 = {}) {
|
|
|
148
148
|
async function generateBundle(options) {
|
|
149
149
|
logger.start('generating html', logLevel);
|
|
150
150
|
try {
|
|
151
|
-
const dir = options.dir
|
|
151
|
+
const dir = options.dir ?? '', fileName = path.relative(dir, fileNameInInitialDir);
|
|
152
152
|
const depromisifiedTemplateString = await templateString, source = await templateFactory(depromisifiedTemplateString, assets, defaultTemplateFactory);
|
|
153
153
|
if (!emitFile || fileName.startsWith('..') || useWriteBundle) {
|
|
154
154
|
if (emitFile && emitFile !== 'auto') {
|
|
@@ -174,19 +174,19 @@ function index (options$1 = {}) {
|
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
async function getAssets(options, bundle) {
|
|
177
|
-
const dir = options.dir
|
|
177
|
+
const dir = options.dir ?? '';
|
|
178
178
|
for (const fileName of Object.keys(bundle)) {
|
|
179
179
|
const relativeToRootAssetPath = path.join(dir, fileName);
|
|
180
|
+
const assetPath = path.relative(initialDir, relativeToRootAssetPath);
|
|
180
181
|
if (ignore(relativeToRootAssetPath) || processedFiles.has(relativeToRootAssetPath)) {
|
|
181
182
|
continue;
|
|
182
183
|
}
|
|
183
184
|
processedFiles.add(relativeToRootAssetPath);
|
|
184
185
|
if (bundle[fileName].type === 'asset') {
|
|
185
|
-
if (await useAssetFactory(
|
|
186
|
+
if (await useAssetFactory(assetPath, relativeToRootAssetPath, bundle[fileName].source, 'asset')) {
|
|
186
187
|
continue;
|
|
187
188
|
}
|
|
188
189
|
if (fileName.endsWith(cssExtention)) {
|
|
189
|
-
const assetPath = path.relative(initialDir, relativeToRootAssetPath);
|
|
190
190
|
assets.asset.push({
|
|
191
191
|
html: shared.getLinkElement(assetPath),
|
|
192
192
|
head: injectIntoHead(relativeToRootAssetPath),
|
|
@@ -198,11 +198,10 @@ function index (options$1 = {}) {
|
|
|
198
198
|
else if (bundle[fileName].type === 'chunk') {
|
|
199
199
|
const chunk = bundle[fileName];
|
|
200
200
|
if (chunk.isEntry) {
|
|
201
|
-
if (await useAssetFactory(
|
|
201
|
+
if (await useAssetFactory(assetPath, relativeToRootAssetPath, chunk.code, options.format)) {
|
|
202
202
|
continue;
|
|
203
203
|
}
|
|
204
204
|
if (options.format === 'es' || options.format === 'iife' || options.format === 'umd') {
|
|
205
|
-
const assetPath = path.relative(initialDir, relativeToRootAssetPath);
|
|
206
205
|
assets[options.format].push({
|
|
207
206
|
html: (assets) => {
|
|
208
207
|
let useConditionalLoading = conditionalLoading;
|
package/dist/index.mjs
CHANGED
|
@@ -67,7 +67,7 @@ function index (options = {}) {
|
|
|
67
67
|
const baseAddInstance = instance.api.addInstance;
|
|
68
68
|
instance.renderStart = function (outputOptions, inputOptions) {
|
|
69
69
|
logger('started collecting information', 0 /* LogLevel.verbose */);
|
|
70
|
-
initialDir = outputOptions.dir
|
|
70
|
+
initialDir = outputOptions.dir ?? '';
|
|
71
71
|
fileNameInInitialDir = path.join(initialDir, outputFile);
|
|
72
72
|
return baseRenderStart.call(this, outputOptions, inputOptions);
|
|
73
73
|
};
|
|
@@ -98,7 +98,7 @@ function index (options = {}) {
|
|
|
98
98
|
.map(({ key, count }) => `${key}: ${count}`)
|
|
99
99
|
.join(', ');
|
|
100
100
|
logger(`assets collected: [${statistics}], remaining: ${remainingOutputsCount} outputs, ${remainingConfigsCount} configs`, 0 /* LogLevel.verbose */);
|
|
101
|
-
const dir = options.dir
|
|
101
|
+
const dir = options.dir ?? '', fileName = path.relative(dir, fileNameInInitialDir);
|
|
102
102
|
if (fileName in bundle) {
|
|
103
103
|
if (useEmittedTemplate) {
|
|
104
104
|
logger(`using exiting emitted ${fileName} as an input for out templateFactory`, 0 /* LogLevel.verbose */);
|
|
@@ -146,7 +146,7 @@ function index (options = {}) {
|
|
|
146
146
|
async function generateBundle(options) {
|
|
147
147
|
logger.start('generating html', logLevel);
|
|
148
148
|
try {
|
|
149
|
-
const dir = options.dir
|
|
149
|
+
const dir = options.dir ?? '', fileName = path.relative(dir, fileNameInInitialDir);
|
|
150
150
|
const depromisifiedTemplateString = await templateString, source = await templateFactory(depromisifiedTemplateString, assets, defaultTemplateFactory);
|
|
151
151
|
if (!emitFile || fileName.startsWith('..') || useWriteBundle) {
|
|
152
152
|
if (emitFile && emitFile !== 'auto') {
|
|
@@ -172,19 +172,19 @@ function index (options = {}) {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
async function getAssets(options, bundle) {
|
|
175
|
-
const dir = options.dir
|
|
175
|
+
const dir = options.dir ?? '';
|
|
176
176
|
for (const fileName of Object.keys(bundle)) {
|
|
177
177
|
const relativeToRootAssetPath = path.join(dir, fileName);
|
|
178
|
+
const assetPath = path.relative(initialDir, relativeToRootAssetPath);
|
|
178
179
|
if (ignore(relativeToRootAssetPath) || processedFiles.has(relativeToRootAssetPath)) {
|
|
179
180
|
continue;
|
|
180
181
|
}
|
|
181
182
|
processedFiles.add(relativeToRootAssetPath);
|
|
182
183
|
if (bundle[fileName].type === 'asset') {
|
|
183
|
-
if (await useAssetFactory(
|
|
184
|
+
if (await useAssetFactory(assetPath, relativeToRootAssetPath, bundle[fileName].source, 'asset')) {
|
|
184
185
|
continue;
|
|
185
186
|
}
|
|
186
187
|
if (fileName.endsWith(cssExtention)) {
|
|
187
|
-
const assetPath = path.relative(initialDir, relativeToRootAssetPath);
|
|
188
188
|
assets.asset.push({
|
|
189
189
|
html: getLinkElement(assetPath),
|
|
190
190
|
head: injectIntoHead(relativeToRootAssetPath),
|
|
@@ -196,11 +196,10 @@ function index (options = {}) {
|
|
|
196
196
|
else if (bundle[fileName].type === 'chunk') {
|
|
197
197
|
const chunk = bundle[fileName];
|
|
198
198
|
if (chunk.isEntry) {
|
|
199
|
-
if (await useAssetFactory(
|
|
199
|
+
if (await useAssetFactory(assetPath, relativeToRootAssetPath, chunk.code, options.format)) {
|
|
200
200
|
continue;
|
|
201
201
|
}
|
|
202
202
|
if (options.format === 'es' || options.format === 'iife' || options.format === 'umd') {
|
|
203
|
-
const assetPath = path.relative(initialDir, relativeToRootAssetPath);
|
|
204
203
|
assets[options.format].push({
|
|
205
204
|
html: (assets) => {
|
|
206
205
|
let useConditionalLoading = conditionalLoading;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.4.
|
|
2
|
+
"version": "1.4.2",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@rollup-extras/plugin-html",
|
|
5
5
|
"author": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@niceties/logger": "^1.1.4",
|
|
56
|
-
"@rollup-extras/utils": "^1.4.
|
|
56
|
+
"@rollup-extras/utils": "^1.4.2"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "pkgbld-internal",
|