1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.rollupBundleFile = void 0;
|
4 | const rollup = require("rollup");
|
5 | const plugin_node_resolve_1 = require("@rollup/plugin-node-resolve");
|
6 | const sourcemaps = require("rollup-plugin-sourcemaps");
|
7 | const commonJs = require("@rollup/plugin-commonjs");
|
8 | const rollupJson = require("@rollup/plugin-json");
|
9 | const log = require("../utils/log");
|
10 | const umd_module_id_strategy_1 = require("./umd-module-id-strategy");
|
11 | const path = require("path");
|
12 |
|
13 | async function rollupBundleFile(opts) {
|
14 | log.debug(`rollup (v${rollup.VERSION}) ${opts.entry} to ${opts.dest} (${opts.format})`);
|
15 |
|
16 | const bundle = await rollup.rollup({
|
17 | context: 'this',
|
18 | external: moduleId => isExternalDependency(moduleId, opts.format),
|
19 | inlineDynamicImports: false,
|
20 | cache: opts.cache,
|
21 | input: opts.entry,
|
22 | plugins: [
|
23 |
|
24 | rollupJson(),
|
25 |
|
26 | plugin_node_resolve_1.default(),
|
27 |
|
28 | commonJs(),
|
29 |
|
30 | sourcemaps(),
|
31 | { transform: opts.transform },
|
32 | ],
|
33 | onwarn: warning => {
|
34 | if (typeof warning === 'string') {
|
35 | log.warn(warning);
|
36 | }
|
37 | else {
|
38 | if (warning.code === 'THIS_IS_UNDEFINED') {
|
39 | return;
|
40 | }
|
41 | log.warn(warning.message);
|
42 | }
|
43 | },
|
44 | preserveSymlinks: true,
|
45 |
|
46 |
|
47 | treeshake: false,
|
48 | });
|
49 |
|
50 | await bundle.write({
|
51 | name: opts.moduleName,
|
52 | format: opts.format,
|
53 | amd: opts.amd,
|
54 | file: opts.dest,
|
55 | banner: '',
|
56 | globals: moduleId => umd_module_id_strategy_1.umdModuleIdStrategy(moduleId, opts.umdModuleIds || {}),
|
57 | sourcemap: true,
|
58 | });
|
59 | return bundle.cache;
|
60 | }
|
61 | exports.rollupBundleFile = rollupBundleFile;
|
62 | function isExternalDependency(moduleId, format) {
|
63 |
|
64 |
|
65 | if (moduleId.startsWith('.') || moduleId.startsWith('/') || path.isAbsolute(moduleId)) {
|
66 |
|
67 | return false;
|
68 | }
|
69 | if (format === 'umd' && moduleId.startsWith('tslib')) {
|
70 | return false;
|
71 | }
|
72 | return true;
|
73 | }
|
74 |
|
\ | No newline at end of file |