UNPKG

2.76 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.rollupBundleFile = void 0;
4const rollup = require("rollup");
5const plugin_node_resolve_1 = require("@rollup/plugin-node-resolve");
6const sourcemaps = require("rollup-plugin-sourcemaps");
7const commonJs = require("@rollup/plugin-commonjs");
8const rollupJson = require("@rollup/plugin-json");
9const log = require("../utils/log");
10const umd_module_id_strategy_1 = require("./umd-module-id-strategy");
11const path = require("path");
12/** Runs rollup over the given entry file, writes a bundle file. */
13async function rollupBundleFile(opts) {
14 log.debug(`rollup (v${rollup.VERSION}) ${opts.entry} to ${opts.dest} (${opts.format})`);
15 // Create the bundle
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 // @ts-ignore
24 rollupJson(),
25 // @ts-ignore
26 plugin_node_resolve_1.default(),
27 // @ts-ignore
28 commonJs(),
29 // @ts-ignore
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 // Disable treeshaking when generating bundles
46 // see: https://github.com/angular/angular/pull/32069
47 treeshake: false,
48 });
49 // Output the bundle to disk
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}
61exports.rollupBundleFile = rollupBundleFile;
62function isExternalDependency(moduleId, format) {
63 // more information about why we don't check for 'node_modules' path
64 // https://github.com/rollup/rollup-plugin-node-resolve/issues/110#issuecomment-350353632
65 if (moduleId.startsWith('.') || moduleId.startsWith('/') || path.isAbsolute(moduleId)) {
66 // if it's either 'absolute', marked to embed, starts with a '.' or '/' or is the umd bundle and is tslib
67 return false;
68 }
69 if (format === 'umd' && moduleId.startsWith('tslib')) {
70 return false;
71 }
72 return true;
73}
74//# sourceMappingURL=rollup.js.map
\No newline at end of file