@qubit-ltd/rollup-builder 1.8.4
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 +201 -0
- package/README.md +335 -0
- package/README.zh_CN.md +288 -0
- package/dist/rollup-builder.cjs +793 -0
- package/dist/rollup-builder.cjs.map +1 -0
- package/dist/rollup-builder.min.cjs +1 -0
- package/dist/rollup-builder.min.cjs.map +1 -0
- package/dist/rollup-builder.min.mjs +1 -0
- package/dist/rollup-builder.min.mjs.map +1 -0
- package/dist/rollup-builder.mjs +791 -0
- package/dist/rollup-builder.mjs.map +1 -0
- package/doc/api/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-Bold-webfont.svg +1838 -0
- package/doc/api/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-BoldItalic-webfont.svg +1838 -0
- package/doc/api/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-Italic-webfont.svg +1838 -0
- package/doc/api/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-Light-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-Light-webfont.svg +1839 -0
- package/doc/api/fonts/OpenSans-Light-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-LightItalic-webfont.svg +1843 -0
- package/doc/api/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-Regular-webfont.svg +1839 -0
- package/doc/api/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-Semibold-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-Semibold-webfont.svg +1838 -0
- package/doc/api/fonts/OpenSans-Semibold-webfont.ttf +0 -0
- package/doc/api/fonts/OpenSans-Semibold-webfont.woff +0 -0
- package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
- package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.svg +1838 -0
- package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
- package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
- package/doc/api/global.html +2913 -0
- package/doc/api/index.html +418 -0
- package/doc/api/scripts/linenumber.js +34 -0
- package/doc/api/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/doc/api/scripts/prettify/lang-css.js +2 -0
- package/doc/api/scripts/prettify/prettify.js +28 -0
- package/doc/api/styles/jsdoc-default.css +699 -0
- package/doc/api/styles/prettify-jsdoc.css +120 -0
- package/doc/api/styles/prettify-tomorrow.css +141 -0
- package/doc/rollup-builder.min.visualization.html +4842 -0
- package/doc/rollup-builder.visualization.html +4842 -0
- package/package.json +85 -0
|
@@ -0,0 +1,791 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import json from '@rollup/plugin-json';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import alias from '@rollup/plugin-alias';
|
|
7
|
+
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
8
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
9
|
+
import babel from '@rollup/plugin-babel';
|
|
10
|
+
import terser from '@rollup/plugin-terser';
|
|
11
|
+
import analyzer from 'rollup-plugin-analyzer';
|
|
12
|
+
import { visualizer } from 'rollup-plugin-visualizer';
|
|
13
|
+
|
|
14
|
+
function _createForOfIteratorHelper$1(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$1(r)) || e) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
15
|
+
function _unsupportedIterableToArray$1(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$1(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$1(r, a) : void 0; } }
|
|
16
|
+
function _arrayLikeToArray$1(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Gets Rollup `external` configuration.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} importMetaUrl
|
|
22
|
+
* The URL of the `import.meta` of the caller module.
|
|
23
|
+
* @param {object} options
|
|
24
|
+
* The additional options for building the library.
|
|
25
|
+
* @returns {function}
|
|
26
|
+
* The predicate used as the Rollup `external` configuration for the library.
|
|
27
|
+
* @author Haixing Hu
|
|
28
|
+
*/
|
|
29
|
+
function getRollupExternal(importMetaUrl, options) {
|
|
30
|
+
var _options$externals;
|
|
31
|
+
if (!importMetaUrl) {
|
|
32
|
+
throw new Error('importMetaUrl is required');
|
|
33
|
+
}
|
|
34
|
+
if (!options) {
|
|
35
|
+
throw new Error('options is required');
|
|
36
|
+
}
|
|
37
|
+
// gets all peerDependencies packages from 'package.json' of the caller module
|
|
38
|
+
var require = createRequire(importMetaUrl);
|
|
39
|
+
var pkg = require('./package.json');
|
|
40
|
+
var peers = _toConsumableArray(Object.keys(pkg.peerDependencies || {}));
|
|
41
|
+
if (!Array.isArray(peers)) {
|
|
42
|
+
throw new Error('peerDependencies should be an array');
|
|
43
|
+
}
|
|
44
|
+
if (peers.length === 0) {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
var peerPattern = peers ? new RegExp("^(".concat(peers.join('|'), ")($|/)")) : null;
|
|
48
|
+
// gets the additional external packages from the user passed options
|
|
49
|
+
var additions = (_options$externals = options.externals) !== null && _options$externals !== void 0 ? _options$externals : [];
|
|
50
|
+
// save some configuration to the options object
|
|
51
|
+
options.peers = peers;
|
|
52
|
+
options.peerPattern = peerPattern;
|
|
53
|
+
return function (id) {
|
|
54
|
+
if (peerPattern && peerPattern.test(id)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
var _iterator = _createForOfIteratorHelper$1(additions),
|
|
58
|
+
_step;
|
|
59
|
+
try {
|
|
60
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
61
|
+
var pattern = _step.value;
|
|
62
|
+
if (pattern instanceof RegExp && pattern.test(id)) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
if ((typeof pattern === 'string' || pattern instanceof String) && pattern === id) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch (err) {
|
|
70
|
+
_iterator.e(err);
|
|
71
|
+
} finally {
|
|
72
|
+
_iterator.f();
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
79
|
+
//
|
|
80
|
+
// Copyright (c) 2022 - 2023.
|
|
81
|
+
// Haixing Hu, Qubit Co. Ltd.
|
|
82
|
+
//
|
|
83
|
+
// All rights reserved.
|
|
84
|
+
//
|
|
85
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Gets the Rollup `output` configuration.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} format
|
|
91
|
+
* The format of the library.
|
|
92
|
+
* @param {string} libraryName
|
|
93
|
+
* The name of the library.
|
|
94
|
+
* @param {object} options
|
|
95
|
+
* The additional options for building the library.
|
|
96
|
+
* @returns {object}
|
|
97
|
+
* The Rollup output configuration for the library.
|
|
98
|
+
* @author Haixing Hu
|
|
99
|
+
*/
|
|
100
|
+
function getRollupOutput(format, libraryName, options) {
|
|
101
|
+
var _options$exports, _options$nodeEnv, _options$minify, _options$filenamePref, _options$outputDir, _options$sourcemap;
|
|
102
|
+
var filenameExt = '';
|
|
103
|
+
var footer = '';
|
|
104
|
+
var exports = (_options$exports = options.exports) !== null && _options$exports !== void 0 ? _options$exports : 'auto';
|
|
105
|
+
switch (format) {
|
|
106
|
+
case 'cjs': // drop down
|
|
107
|
+
case 'umd':
|
|
108
|
+
// drop down
|
|
109
|
+
filenameExt = format === 'cjs' ? '.cjs' : ".".concat(format, ".js");
|
|
110
|
+
// The following workaround is to solve the following issue: If an ESM
|
|
111
|
+
// module has both default export and named exports, the rollup cannot
|
|
112
|
+
// handle it correctly. For example, the following is a source ESM module:
|
|
113
|
+
// ```js
|
|
114
|
+
// export { Foo, Bar };
|
|
115
|
+
// export default Foo;
|
|
116
|
+
// ```
|
|
117
|
+
// The rollup will translate it into the following codes:
|
|
118
|
+
// ```js
|
|
119
|
+
// exports.Foo = Foo;
|
|
120
|
+
// exports.Bar = Bar;
|
|
121
|
+
// exports.default = Foo;
|
|
122
|
+
// ```
|
|
123
|
+
// However, a common-js consumer will use the module as follows:
|
|
124
|
+
// ```js
|
|
125
|
+
// const Foo = require('my-module');
|
|
126
|
+
// ```
|
|
127
|
+
// which will cause an error. The correct usage should be
|
|
128
|
+
// ```js
|
|
129
|
+
// const Foo = require('my-module').default
|
|
130
|
+
// ```
|
|
131
|
+
// But unfortunately, the rollup will translate the ESM default import as
|
|
132
|
+
// follows:
|
|
133
|
+
// ```js
|
|
134
|
+
// import Foo from 'my-module';
|
|
135
|
+
// ```
|
|
136
|
+
// will be translated by rollup to
|
|
137
|
+
// ```js
|
|
138
|
+
// const Foo = require('my-module');
|
|
139
|
+
// ```
|
|
140
|
+
// Note that the above translation has no `.default` suffix, which will
|
|
141
|
+
// cause an error.
|
|
142
|
+
//
|
|
143
|
+
// The workaround is copied from the source code of the official rollup
|
|
144
|
+
// plugins:
|
|
145
|
+
// https://github.com/rollup/plugins/blob/master/shared/rollup.config.mjs
|
|
146
|
+
//
|
|
147
|
+
// It adds a simple footer statements to each `CJS` format bundle:
|
|
148
|
+
// ```js
|
|
149
|
+
// module.exports = Object.assign(exports.default, exports);
|
|
150
|
+
// ```
|
|
151
|
+
//
|
|
152
|
+
// See:
|
|
153
|
+
// [1] https://rollupjs.org/configuration-options/#output-exports
|
|
154
|
+
// [2] https://github.com/rollup/rollup/issues/1961
|
|
155
|
+
// [3] https://stackoverflow.com/questions/58246998/mixing-default-and-named-exports-with-rollup
|
|
156
|
+
// [4] https://github.com/avisek/rollup-patch-seamless-default-export
|
|
157
|
+
// [5] https://github.com/rollup/plugins/blob/master/shared/rollup.config.mjs
|
|
158
|
+
//
|
|
159
|
+
if (exports === 'mixed') {
|
|
160
|
+
exports = 'named';
|
|
161
|
+
footer = 'module.exports = Object.assign(exports.default, exports);';
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
case 'amd': // drop down
|
|
165
|
+
case 'iife':
|
|
166
|
+
filenameExt = ".".concat(format, ".js");
|
|
167
|
+
if (exports === 'mixed') {
|
|
168
|
+
exports = 'auto';
|
|
169
|
+
}
|
|
170
|
+
break;
|
|
171
|
+
case 'es': // drop down
|
|
172
|
+
case 'esm': // drop down
|
|
173
|
+
case 'module':
|
|
174
|
+
format = 'es';
|
|
175
|
+
filenameExt = '.mjs';
|
|
176
|
+
// fix the exports, because the ESM format does not support the 'mixed' exports mode
|
|
177
|
+
if (exports === 'mixed') {
|
|
178
|
+
exports = 'auto';
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
throw new Error("Unsupported library format: ".concat(format));
|
|
183
|
+
}
|
|
184
|
+
var nodeEnv = (_options$nodeEnv = options.nodeEnv) !== null && _options$nodeEnv !== void 0 ? _options$nodeEnv : process.env.NODE_ENV;
|
|
185
|
+
var minify = (_options$minify = options.minify) !== null && _options$minify !== void 0 ? _options$minify : nodeEnv === 'production';
|
|
186
|
+
var camelCaseToDashCase = function camelCaseToDashCase(s) {
|
|
187
|
+
return s.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
188
|
+
};
|
|
189
|
+
var filenamePrefix = (_options$filenamePref = options.filenamePrefix) !== null && _options$filenamePref !== void 0 ? _options$filenamePref : camelCaseToDashCase(libraryName);
|
|
190
|
+
var filenameBase = "".concat(filenamePrefix).concat(minify ? '.min' : '');
|
|
191
|
+
var filename = "".concat(filenameBase).concat(filenameExt);
|
|
192
|
+
var outputDir = (_options$outputDir = options.outputDir) !== null && _options$outputDir !== void 0 ? _options$outputDir : 'dist';
|
|
193
|
+
var sourcemap = (_options$sourcemap = options.sourcemap) !== null && _options$sourcemap !== void 0 ? _options$sourcemap : true;
|
|
194
|
+
// save some configuration to the options object
|
|
195
|
+
options.format = format;
|
|
196
|
+
options.name = libraryName;
|
|
197
|
+
options.minify = minify;
|
|
198
|
+
options.filenamePrefix = filenamePrefix;
|
|
199
|
+
options.filenameBase = filenameBase;
|
|
200
|
+
options.filenameExt = filenameExt;
|
|
201
|
+
options.filename = filename;
|
|
202
|
+
options.exports = exports;
|
|
203
|
+
options.sourcemap = sourcemap;
|
|
204
|
+
options.outputDir = outputDir;
|
|
205
|
+
return {
|
|
206
|
+
name: libraryName,
|
|
207
|
+
file: "".concat(outputDir, "/").concat(filename),
|
|
208
|
+
format: format,
|
|
209
|
+
exports: exports,
|
|
210
|
+
footer: footer,
|
|
211
|
+
sourcemap: sourcemap,
|
|
212
|
+
compact: minify
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
217
|
+
//
|
|
218
|
+
// Copyright (c) 2022 - 2023.
|
|
219
|
+
// Haixing Hu, Qubit Co. Ltd.
|
|
220
|
+
//
|
|
221
|
+
// All rights reserved.
|
|
222
|
+
//
|
|
223
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Configures the `@rollup/plugin-alias` plugin.
|
|
227
|
+
*
|
|
228
|
+
* @param {string} format
|
|
229
|
+
* The format of the library.
|
|
230
|
+
* @param {string} importMetaUrl
|
|
231
|
+
* The URL of the `import.meta` of the caller module.
|
|
232
|
+
* @param {object} options
|
|
233
|
+
* The additional options for building the library.
|
|
234
|
+
* @param {Array<Object>} plugins
|
|
235
|
+
* The Rollup plugins array.
|
|
236
|
+
* @returns {Array<Object>}
|
|
237
|
+
* The modified Rollup plugins array.
|
|
238
|
+
* @author Haixing Hu
|
|
239
|
+
* @see https://www.npmjs.com/package/@rollup/plugin-alias
|
|
240
|
+
*/
|
|
241
|
+
function configAliasPlugin(format, importMetaUrl, options, plugins) {
|
|
242
|
+
var _options$useAliasPlug;
|
|
243
|
+
if ((_options$useAliasPlug = options.useAliasPlugin) !== null && _options$useAliasPlug !== void 0 ? _options$useAliasPlug : true) {
|
|
244
|
+
var _options$aliasPluginO;
|
|
245
|
+
// The @rollup/plugin-alias enables us to use absolute import paths for
|
|
246
|
+
// "src" (or any other path you want to configure).
|
|
247
|
+
var pluginOptions = (_options$aliasPluginO = options.aliasPluginOptions) !== null && _options$aliasPluginO !== void 0 ? _options$aliasPluginO : {
|
|
248
|
+
entries: {
|
|
249
|
+
'src': fileURLToPath(new URL('src', importMetaUrl))
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
if (options.debug === true) {
|
|
253
|
+
console.debug('[DEBUG] The @rollup/plugin-alias plugin options are:');
|
|
254
|
+
console.dir(pluginOptions, {
|
|
255
|
+
depth: null
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
plugins.push(alias(pluginOptions));
|
|
259
|
+
}
|
|
260
|
+
return plugins;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
264
|
+
//
|
|
265
|
+
// Copyright (c) 2022 - 2023.
|
|
266
|
+
// Haixing Hu, Qubit Co. Ltd.
|
|
267
|
+
//
|
|
268
|
+
// All rights reserved.
|
|
269
|
+
//
|
|
270
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Configures the `@rollup/plugin-node-resolve` plugin.
|
|
274
|
+
*
|
|
275
|
+
* @param {string} format
|
|
276
|
+
* The format of the library.
|
|
277
|
+
* @param {string} importMetaUrl
|
|
278
|
+
* The URL of the `import.meta` of the caller module.
|
|
279
|
+
* @param {object} options
|
|
280
|
+
* The additional options for building the library.
|
|
281
|
+
* @param {Array<Object>} plugins
|
|
282
|
+
* The Rollup plugins array.
|
|
283
|
+
* @returns {Array<Object>}
|
|
284
|
+
* The modified Rollup plugins array.
|
|
285
|
+
* @author Haixing Hu
|
|
286
|
+
* @see https://www.npmjs.com/package/@rollup/plugin-node-resolve
|
|
287
|
+
*/
|
|
288
|
+
function configNodeResolvePlugin(format, importMetaUrl, options, plugins) {
|
|
289
|
+
var _options$useNodeResol;
|
|
290
|
+
if ((_options$useNodeResol = options.useNodeResolvePlugin) !== null && _options$useNodeResol !== void 0 ? _options$useNodeResol : true) {
|
|
291
|
+
var _options$nodeResolveP;
|
|
292
|
+
// The @rollup/plugin-node-resolve allows Rollup to resolve external
|
|
293
|
+
// modules from node_modules:
|
|
294
|
+
var pluginOptions = (_options$nodeResolveP = options.nodeResolvePluginOptions) !== null && _options$nodeResolveP !== void 0 ? _options$nodeResolveP : {};
|
|
295
|
+
if (options.debug === true) {
|
|
296
|
+
console.debug('[DEBUG] The @rollup/plugin-node-resolve plugin options are:');
|
|
297
|
+
console.dir(pluginOptions, {
|
|
298
|
+
depth: null
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
plugins.push(nodeResolve(pluginOptions));
|
|
302
|
+
}
|
|
303
|
+
return plugins;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
307
|
+
//
|
|
308
|
+
// Copyright (c) 2022 - 2023.
|
|
309
|
+
// Haixing Hu, Qubit Co. Ltd.
|
|
310
|
+
//
|
|
311
|
+
// All rights reserved.
|
|
312
|
+
//
|
|
313
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Configures the `@rollup/plugin-commonjs` plugin.
|
|
317
|
+
*
|
|
318
|
+
* @param {string} format
|
|
319
|
+
* The format of the library.
|
|
320
|
+
* @param {string} importMetaUrl
|
|
321
|
+
* The URL of the `import.meta` of the caller module.
|
|
322
|
+
* @param {object} options
|
|
323
|
+
* The additional options for building the library.
|
|
324
|
+
* @param {Array<Object>} plugins
|
|
325
|
+
* The Rollup plugins array.
|
|
326
|
+
* @returns {Array<Object>}
|
|
327
|
+
* The modified Rollup plugins array.
|
|
328
|
+
* @author Haixing Hu
|
|
329
|
+
* @see https://www.npmjs.com/package/@rollup/plugin-commonjs
|
|
330
|
+
*/
|
|
331
|
+
function configCommonJsPlugin(format, importMetaUrl, options, plugins) {
|
|
332
|
+
var _options$useCommonjsP;
|
|
333
|
+
if ((_options$useCommonjsP = options.useCommonjsPlugin) !== null && _options$useCommonjsP !== void 0 ? _options$useCommonjsP : true) {
|
|
334
|
+
var _options$commonjsPlug;
|
|
335
|
+
// The @rollup/plugin-commonjs plugin converts 3rd-party CommonJS modules
|
|
336
|
+
// into ES6 code, so that they can be included in our Rollup bundle.
|
|
337
|
+
// When using @rollup/plugin-babel with @rollup/plugin-commonjs in the
|
|
338
|
+
// same Rollup configuration, it's important to note that
|
|
339
|
+
// @rollup/plugin-commonjs must be placed before this plugin in the
|
|
340
|
+
// plugins array for the two to work together properly.
|
|
341
|
+
var pluginOptions = (_options$commonjsPlug = options.commonjsPluginOptions) !== null && _options$commonjsPlug !== void 0 ? _options$commonjsPlug : {
|
|
342
|
+
include: ['node_modules/**']
|
|
343
|
+
};
|
|
344
|
+
if (options.debug === true) {
|
|
345
|
+
console.debug('[DEBUG] The @rollup/plugin-commonjs plugin options are:');
|
|
346
|
+
console.dir(pluginOptions, {
|
|
347
|
+
depth: null
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
plugins.push(commonjs(pluginOptions));
|
|
351
|
+
}
|
|
352
|
+
return plugins;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
356
|
+
//
|
|
357
|
+
// Copyright (c) 2022 - 2023.
|
|
358
|
+
// Haixing Hu, Qubit Co. Ltd.
|
|
359
|
+
//
|
|
360
|
+
// All rights reserved.
|
|
361
|
+
//
|
|
362
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Configures the `@rollup/plugin-babel` plugin.
|
|
366
|
+
*
|
|
367
|
+
* @param {string} format
|
|
368
|
+
* The format of the library.
|
|
369
|
+
* @param {string} importMetaUrl
|
|
370
|
+
* The URL of the `import.meta` of the caller module.
|
|
371
|
+
* @param {object} options
|
|
372
|
+
* The additional options for building the library.
|
|
373
|
+
* @param {Array} plugins
|
|
374
|
+
* The array of Rollup plugins.
|
|
375
|
+
* @returns {Array<Object>}
|
|
376
|
+
* The modified Rollup plugins array.
|
|
377
|
+
* @author Haixing Hu
|
|
378
|
+
* @see https://www.npmjs.com/package/@rollup/plugin-babel
|
|
379
|
+
*/
|
|
380
|
+
function configBabelPlugin(format, importMetaUrl, options, plugins) {
|
|
381
|
+
var _options$useBabelPlug;
|
|
382
|
+
if ((_options$useBabelPlug = options.useBabelPlugin) !== null && _options$useBabelPlug !== void 0 ? _options$useBabelPlug : true) {
|
|
383
|
+
var _options$babelPluginO;
|
|
384
|
+
var pluginOptions = (_options$babelPluginO = options.babelPluginOptions) !== null && _options$babelPluginO !== void 0 ? _options$babelPluginO : {
|
|
385
|
+
babelHelpers: 'runtime',
|
|
386
|
+
exclude: ['node_modules/**'],
|
|
387
|
+
presets: [
|
|
388
|
+
// The @babel/preset-env preset enables Babel to transpile ES6+ code
|
|
389
|
+
// and the rollup requires that Babel keeps ES6 module syntax intact.
|
|
390
|
+
['@babel/preset-env', {
|
|
391
|
+
modules: false
|
|
392
|
+
}]],
|
|
393
|
+
plugins: ['@babel/plugin-transform-runtime']
|
|
394
|
+
};
|
|
395
|
+
if (options.debug === true) {
|
|
396
|
+
console.debug('[DEBUG] The @rollup/plugin-babel plugin options are:');
|
|
397
|
+
console.dir(pluginOptions, {
|
|
398
|
+
depth: null
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
plugins.push(babel(pluginOptions));
|
|
402
|
+
}
|
|
403
|
+
return plugins;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
407
|
+
//
|
|
408
|
+
// Copyright (c) 2022 - 2023.
|
|
409
|
+
// Haixing Hu, Qubit Co. Ltd.
|
|
410
|
+
//
|
|
411
|
+
// All rights reserved.
|
|
412
|
+
//
|
|
413
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Configures the `@rollup/plugin-terser` plugin.
|
|
417
|
+
*
|
|
418
|
+
* @param {string} format
|
|
419
|
+
* The format of the library.
|
|
420
|
+
* @param {string} importMetaUrl
|
|
421
|
+
* The URL of the `import.meta` of the caller module.
|
|
422
|
+
* @param {object} options
|
|
423
|
+
* The additional options for building the library.
|
|
424
|
+
* @param {Array} plugins
|
|
425
|
+
* The array of Rollup plugins.
|
|
426
|
+
* @returns {Array<Object>}
|
|
427
|
+
* The modified Rollup plugins array.
|
|
428
|
+
* @author Haixing Hu
|
|
429
|
+
* @see https://www.npmjs.com/package/@rollup/plugin-terser
|
|
430
|
+
*/
|
|
431
|
+
function configTerserPlugin(format, importMetaUrl, options, plugins) {
|
|
432
|
+
var _options$nodeEnv, _options$minify;
|
|
433
|
+
var nodeEnv = (_options$nodeEnv = options.nodeEnv) !== null && _options$nodeEnv !== void 0 ? _options$nodeEnv : process.env.NODE_ENV;
|
|
434
|
+
var minify = (_options$minify = options.minify) !== null && _options$minify !== void 0 ? _options$minify : nodeEnv === 'production';
|
|
435
|
+
if (minify) {
|
|
436
|
+
var _options$terserPlugin;
|
|
437
|
+
// The @rollup/plugin-terser uses terser under the hood to minify the code.
|
|
438
|
+
var pluginOptions = (_options$terserPlugin = options.terserPluginOptions) !== null && _options$terserPlugin !== void 0 ? _options$terserPlugin : {
|
|
439
|
+
output: {
|
|
440
|
+
comments: false // default to remove all comments
|
|
441
|
+
},
|
|
442
|
+
keep_classnames: true,
|
|
443
|
+
// keep the class names
|
|
444
|
+
keep_fnames: true // keep the function names
|
|
445
|
+
};
|
|
446
|
+
if (options.debug === true) {
|
|
447
|
+
console.debug('[DEBUG] The @rollup/plugin-terser plugin options are:');
|
|
448
|
+
console.dir(pluginOptions, {
|
|
449
|
+
depth: null
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
plugins.push(terser(pluginOptions));
|
|
453
|
+
}
|
|
454
|
+
return plugins;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
458
|
+
//
|
|
459
|
+
// Copyright (c) 2022 - 2023.
|
|
460
|
+
// Haixing Hu, Qubit Co. Ltd.
|
|
461
|
+
//
|
|
462
|
+
// All rights reserved.
|
|
463
|
+
//
|
|
464
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Configures the `rollup-plugin-analyzer` plugin.
|
|
468
|
+
*
|
|
469
|
+
* @param {string} format
|
|
470
|
+
* The format of the library.
|
|
471
|
+
* @param {string} importMetaUrl
|
|
472
|
+
* The URL of the `import.meta` of the caller module.
|
|
473
|
+
* @param {object} options
|
|
474
|
+
* The additional options for building the library.
|
|
475
|
+
* @param {Array} plugins
|
|
476
|
+
* The array of Rollup plugins.
|
|
477
|
+
* @returns {Array<Object>}
|
|
478
|
+
* The modified Rollup plugins array.
|
|
479
|
+
* @author Haixing Hu
|
|
480
|
+
* @see https://www.npmjs.com/package/rollup-plugin-analyzer
|
|
481
|
+
*/
|
|
482
|
+
function configAnalyzerPlugin(format, importMetaUrl, options, plugins) {
|
|
483
|
+
var _options$useAnalyzerP;
|
|
484
|
+
if ((_options$useAnalyzerP = options.useAnalyzerPlugin) !== null && _options$useAnalyzerP !== void 0 ? _options$useAnalyzerP : true) {
|
|
485
|
+
var _options$analyzerPlug;
|
|
486
|
+
// The rollup-plugin-analyzer will print out some useful info about our
|
|
487
|
+
// generated bundle upon successful builds.
|
|
488
|
+
var pluginOptions = (_options$analyzerPlug = options.analyzerPluginOptions) !== null && _options$analyzerPlug !== void 0 ? _options$analyzerPlug : {
|
|
489
|
+
hideDeps: true,
|
|
490
|
+
limit: 0,
|
|
491
|
+
summaryOnly: true
|
|
492
|
+
};
|
|
493
|
+
if (options.debug === true) {
|
|
494
|
+
console.debug('[DEBUG] The rollup-plugin-analyzer plugin options are:');
|
|
495
|
+
console.dir(pluginOptions, {
|
|
496
|
+
depth: null
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
plugins.push(analyzer(pluginOptions));
|
|
500
|
+
}
|
|
501
|
+
return plugins;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
505
|
+
//
|
|
506
|
+
// Copyright (c) 2022 - 2023.
|
|
507
|
+
// Haixing Hu, Qubit Co. Ltd.
|
|
508
|
+
//
|
|
509
|
+
// All rights reserved.
|
|
510
|
+
//
|
|
511
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Configures the `rollup-plugin-visualizer` plugin.
|
|
515
|
+
*
|
|
516
|
+
* The `rollup-plugin-visualizer` will visualize and analyze your Rollup
|
|
517
|
+
* bundle to see which modules are taking up space.
|
|
518
|
+
*
|
|
519
|
+
* @param {string} format
|
|
520
|
+
* The format of the library.
|
|
521
|
+
* @param {string} importMetaUrl
|
|
522
|
+
* The URL of the `import.meta` of the caller module.
|
|
523
|
+
* @param {object} options
|
|
524
|
+
* The additional options for building the library.
|
|
525
|
+
* @param {Array} plugins
|
|
526
|
+
* The array of Rollup plugins.
|
|
527
|
+
* @returns {Array<Object>}
|
|
528
|
+
* The modified Rollup plugins array.
|
|
529
|
+
* @author Haixing Hu
|
|
530
|
+
* @see https://www.npmjs.com/package/rollup-plugin-visualizer
|
|
531
|
+
*/
|
|
532
|
+
function configVisualizerPlugin(format, importMetaUrl, options, plugins) {
|
|
533
|
+
var _options$useVisualize;
|
|
534
|
+
if ((_options$useVisualize = options.useVisualizerPlugin) !== null && _options$useVisualize !== void 0 ? _options$useVisualize : true) {
|
|
535
|
+
var _options$visualizerPl;
|
|
536
|
+
// The rollup-plugin-visualizer will visualize and analyze your Rollup
|
|
537
|
+
// bundle to see which modules are taking up space.
|
|
538
|
+
var pluginOptions = (_options$visualizerPl = options.visualizerPluginOptions) !== null && _options$visualizerPl !== void 0 ? _options$visualizerPl : {
|
|
539
|
+
filename: "./doc/".concat(options.filenameBase, ".visualization.html"),
|
|
540
|
+
gzipSize: true,
|
|
541
|
+
brotliSize: true
|
|
542
|
+
};
|
|
543
|
+
if (options.debug === true) {
|
|
544
|
+
console.debug('[DEBUG] The rollup-plugin-visualizer plugin options are:');
|
|
545
|
+
console.dir(pluginOptions, {
|
|
546
|
+
depth: null
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
plugins.push(visualizer(pluginOptions));
|
|
550
|
+
}
|
|
551
|
+
return plugins;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Gets Rollup `plugins` configuration.
|
|
556
|
+
*
|
|
557
|
+
* @param {string} format
|
|
558
|
+
* The format of the library.
|
|
559
|
+
* @param {string} importMetaUrl
|
|
560
|
+
* The URL of the `import.meta` of the caller module.
|
|
561
|
+
* @param {object} options
|
|
562
|
+
* The additional options for building the library.
|
|
563
|
+
* @returns {Array<Object>}
|
|
564
|
+
* The Rollup plugins array.
|
|
565
|
+
* @author Haixing Hu
|
|
566
|
+
*/
|
|
567
|
+
function getRollupPlugins(format, importMetaUrl, options) {
|
|
568
|
+
var plugins = [];
|
|
569
|
+
plugins.push(json());
|
|
570
|
+
configAliasPlugin(format, importMetaUrl, options, plugins);
|
|
571
|
+
configNodeResolvePlugin(format, importMetaUrl, options, plugins);
|
|
572
|
+
configCommonJsPlugin(format, importMetaUrl, options, plugins);
|
|
573
|
+
configBabelPlugin(format, importMetaUrl, options, plugins);
|
|
574
|
+
configTerserPlugin(format, importMetaUrl, options, plugins);
|
|
575
|
+
configAnalyzerPlugin(format, importMetaUrl, options, plugins);
|
|
576
|
+
configVisualizerPlugin(format, importMetaUrl, options, plugins);
|
|
577
|
+
// The user can specify additional plugins.
|
|
578
|
+
if (options.plugins) {
|
|
579
|
+
plugins.push.apply(plugins, _toConsumableArray(options.plugins));
|
|
580
|
+
}
|
|
581
|
+
return plugins;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
585
|
+
//
|
|
586
|
+
// Copyright (c) 2022 - 2024.
|
|
587
|
+
// Haixing Hu, Qubit Co. Ltd.
|
|
588
|
+
//
|
|
589
|
+
// All rights reserved.
|
|
590
|
+
//
|
|
591
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
592
|
+
|
|
593
|
+
function getRollupOnWarn() {
|
|
594
|
+
return function onWarn(warning, warn) {
|
|
595
|
+
// skip certain warnings
|
|
596
|
+
if (warning.code === 'INVALID_ANNOTATION' && warning.message.includes('#__PURE__') && warning.message.includes('terser')) {
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.message.includes('node_modules')) {
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
// Use default for everything else
|
|
603
|
+
warn(warning);
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
608
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
609
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
610
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
611
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Builds the Rollup configuration for a library.
|
|
615
|
+
*
|
|
616
|
+
* The function could be provided with an additional options for building the
|
|
617
|
+
* library. It can have the following fields:
|
|
618
|
+
*
|
|
619
|
+
* - `debug: boolean`: whether to print the debug information. If this field is
|
|
620
|
+
* not specified, the default value is `false`.
|
|
621
|
+
* - `formats: [string]`: the array of formats of the library. It can be an
|
|
622
|
+
* array of the following values:
|
|
623
|
+
* - `'cjs'`: the CommonJS format.
|
|
624
|
+
* - `'umd'`: the UMD format.
|
|
625
|
+
* - `'esm'`: the ES module format.
|
|
626
|
+
*
|
|
627
|
+
* If this field is not specified, the default value is `['cjs', 'esm']`.
|
|
628
|
+
* - `exports: string`: the export mode to use. It can be one of the following
|
|
629
|
+
* values:
|
|
630
|
+
* - `'auto'`: automatically guesses your intentions based on what the input
|
|
631
|
+
* module exports.
|
|
632
|
+
* - `'default'`: if you are only exporting one thing using `export default ...`;
|
|
633
|
+
* note that this can cause issues when generating CommonJS output that is
|
|
634
|
+
* meant to be interchangeable with ESM output.
|
|
635
|
+
* - `'named'`: if you are using named exports.
|
|
636
|
+
* - `'none'`: if you are not exporting anything (e.g. you are building an
|
|
637
|
+
* app, not a library)
|
|
638
|
+
* - `'mixed'`: if you are using named exports mixed with a default export.
|
|
639
|
+
* Note that this is not a standard exports mode officially supported by
|
|
640
|
+
* the `rollup`, instead, it is an additional mode add by this library.
|
|
641
|
+
*
|
|
642
|
+
* See [output.exports](https://rollupjs.org/configuration-options/#output-exports)
|
|
643
|
+
* for more details. If this field is not specified, the default value is
|
|
644
|
+
* `'auto'`.
|
|
645
|
+
* - `nodeEnv: string`: the value of the `NODE_ENV` environment variable. If
|
|
646
|
+
* this field is not specified, the default value is `process.env.NODE_ENV`.
|
|
647
|
+
* - `minify: boolean`: whether to minify the code. If this field is not
|
|
648
|
+
* specified, and the `nodeEnv` is `production`, the default value is `true`;
|
|
649
|
+
* otherwise the default value is `false`.
|
|
650
|
+
* - `sourcemap: boolean`: whether to generate the source map. If this field is
|
|
651
|
+
* not specified, the default value is `true`.
|
|
652
|
+
* - `input: string`: the input file of the library. If this field is not
|
|
653
|
+
* specified, the default value is `src/index.js`.
|
|
654
|
+
* - `outputDir: string`: the output directory of the library. If this field is
|
|
655
|
+
* not specified, the default value is `dist`.
|
|
656
|
+
* - `filenamePrefix: string`: the prefix of the output filename. If this field
|
|
657
|
+
* is not specified, the default value is the dash case of the library name.
|
|
658
|
+
* For example, if the library name is `MyLibrary`, the default value of this
|
|
659
|
+
* field is `my-library`.
|
|
660
|
+
* - `externals: [string]`: the array of additional external packages, each can
|
|
661
|
+
* be specified with either a string or a regular expression. If this field is
|
|
662
|
+
* not specified, the default value is an empty array.
|
|
663
|
+
* - `useAliasPlugin: boolean`: whether to use the `@rollup/plugin-alias` plugin.
|
|
664
|
+
* If this field is not specified, the default value is `true`.
|
|
665
|
+
* - `aliasPluginOptions: object`: the options for the `@rollup/plugin-alias`
|
|
666
|
+
* plugin. If this field is not specified, the default value is:
|
|
667
|
+
* ```js
|
|
668
|
+
* {
|
|
669
|
+
* entries: {
|
|
670
|
+
* 'src': fileURLToPath(new URL('src', importMetaUrl)),
|
|
671
|
+
* },
|
|
672
|
+
* }
|
|
673
|
+
* ```
|
|
674
|
+
* - `useNodeResolvePlugin: boolean`: whether to use the `@rollup/plugin-node-resolve`
|
|
675
|
+
* plugin. If this field is not specified, the default value is `true`.
|
|
676
|
+
* - `nodeResolvePluginOptions: object`: the options for the `@rollup/plugin-node-resolve`
|
|
677
|
+
* plugin. If this field is not specified, the default value is: `{}`.
|
|
678
|
+
* - `useCommonjsPlugin: boolean`: whether to use the `@rollup/plugin-commonjs`
|
|
679
|
+
* plugin. If this field is not specified, the default value is `true`.
|
|
680
|
+
* - `commonjsPluginOptions: object`: the options for the `@rollup/plugin-commonjs`
|
|
681
|
+
* plugin. If this field is not specified, the default value is:
|
|
682
|
+
* ```js
|
|
683
|
+
* {
|
|
684
|
+
* include: ['node_modules/**'],
|
|
685
|
+
* }
|
|
686
|
+
* ```
|
|
687
|
+
* - `useBabelPlugin: boolean`: whether to use the `@rollup/plugin-babel` plugin.
|
|
688
|
+
* If this field is not specified, the default value is `true`.
|
|
689
|
+
* - `babelPluginOptions: object`: the options for the `@rollup/plugin-babel`
|
|
690
|
+
* plugin. If this field is not specified, the default value is:
|
|
691
|
+
* ```js
|
|
692
|
+
* {
|
|
693
|
+
* babelHelpers: 'runtime',
|
|
694
|
+
* exclude: ['node_modules/**'],
|
|
695
|
+
* presets: [
|
|
696
|
+
* '@babel/preset-env',
|
|
697
|
+
* ],
|
|
698
|
+
* plugins: [
|
|
699
|
+
* '@babel/plugin-transform-runtime',
|
|
700
|
+
* ],
|
|
701
|
+
* }
|
|
702
|
+
* ```
|
|
703
|
+
* Note that when using the `@rollup/plugin-babel` plugin, you can also specify
|
|
704
|
+
* the configuration of Babel in the standard Babel configuration files,
|
|
705
|
+
* such as `babel.config.js`, `.babelrc`, etc.
|
|
706
|
+
* - `terserOptions: object`: the options for the `@rollup/plugin-terser` plugin.
|
|
707
|
+
* If this field is not specified, the default value is: `{}`. Whether to use
|
|
708
|
+
* the `@rollup/plugin-terser` plugin depends on the `minify` field of the
|
|
709
|
+
* options or the `NODE_ENV` environment variable.
|
|
710
|
+
* - `useAnalyzerPlugin: boolean`: whether to use the `rollup-plugin-analyzer`
|
|
711
|
+
* plugin. If this field is not specified, the default value is `true`.
|
|
712
|
+
* - `analyzerOptions: object`: the options for the `rollup-plugin-analyzer`
|
|
713
|
+
* plugin. If this field is not specified, the default value is:
|
|
714
|
+
* ```js
|
|
715
|
+
* {
|
|
716
|
+
* hideDeps: true,
|
|
717
|
+
* limit: 0,
|
|
718
|
+
* summaryOnly: true,
|
|
719
|
+
* }
|
|
720
|
+
* ```
|
|
721
|
+
* - `plugins: [object]`: the array of configuration of additional Rollup
|
|
722
|
+
* plugins. If this field is not specified, the default value is an empty
|
|
723
|
+
* array.
|
|
724
|
+
*
|
|
725
|
+
* @param {string} libraryName
|
|
726
|
+
* The name of the library, which will be used as the name of the global
|
|
727
|
+
* variable in the UMD format. It should in the camel case.
|
|
728
|
+
* @param {string} importMetaUrl
|
|
729
|
+
* The URL of the `import.meta` of the caller module. It **MUST** be passed
|
|
730
|
+
* with the `import.meta.url` of the caller module.
|
|
731
|
+
* @param {object} options
|
|
732
|
+
* The additional options for building the library, as described above.
|
|
733
|
+
* @returns {Array<object>}
|
|
734
|
+
* the array of Rollup configurations for the library.
|
|
735
|
+
*/
|
|
736
|
+
function rollupBuilder(libraryName, importMetaUrl) {
|
|
737
|
+
var _options$formats, _options$input;
|
|
738
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
739
|
+
var formats = (_options$formats = options.formats) !== null && _options$formats !== void 0 ? _options$formats : ['cjs', 'esm'];
|
|
740
|
+
var result = [];
|
|
741
|
+
var input = (_options$input = options.input) !== null && _options$input !== void 0 ? _options$input : 'src/index.js';
|
|
742
|
+
var _iterator = _createForOfIteratorHelper(formats),
|
|
743
|
+
_step;
|
|
744
|
+
try {
|
|
745
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
746
|
+
var format = _step.value;
|
|
747
|
+
var clonedOptions = _objectSpread({}, options);
|
|
748
|
+
var output = getRollupOutput(format, libraryName, clonedOptions);
|
|
749
|
+
var external = getRollupExternal(importMetaUrl, clonedOptions);
|
|
750
|
+
var plugins = getRollupPlugins(format, importMetaUrl, clonedOptions);
|
|
751
|
+
var onwarn = getRollupOnWarn();
|
|
752
|
+
var config = {
|
|
753
|
+
input: input,
|
|
754
|
+
output: output,
|
|
755
|
+
external: external,
|
|
756
|
+
plugins: plugins,
|
|
757
|
+
onwarn: onwarn
|
|
758
|
+
};
|
|
759
|
+
result.push(config);
|
|
760
|
+
if (options.debug === true) {
|
|
761
|
+
console.debug("[DEBUG] The options for the format ".concat(format, " is:"));
|
|
762
|
+
console.dir(clonedOptions, {
|
|
763
|
+
depth: null
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
} catch (err) {
|
|
768
|
+
_iterator.e(err);
|
|
769
|
+
} finally {
|
|
770
|
+
_iterator.f();
|
|
771
|
+
}
|
|
772
|
+
if (options.debug === true) {
|
|
773
|
+
console.debug('[DEBUG] The generated rollup configurations are:');
|
|
774
|
+
console.dir(result, {
|
|
775
|
+
depth: null
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
return result;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
782
|
+
//
|
|
783
|
+
// Copyright (c) 2022 - 2023.
|
|
784
|
+
// Haixing Hu, Qubit Co. Ltd.
|
|
785
|
+
//
|
|
786
|
+
// All rights reserved.
|
|
787
|
+
//
|
|
788
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
789
|
+
|
|
790
|
+
export { rollupBuilder as default };
|
|
791
|
+
//# sourceMappingURL=rollup-builder.mjs.map
|