UNPKG

2.38 kBJavaScriptView Raw
1import { pathnameToOperatingSystemPath } from "@jsenv/operating-system-path"
2import { createLogger } from "@jsenv/logger"
3import { createJsenvRollupPlugin } from "./jsenv-rollup-plugin.js"
4import { generateBundleUsingRollup } from "./generate-bundle-using-rollup.js"
5import { formatToRollupFormat } from "./format-to-rollup-format.js"
6
7export const bundleWithoutBalancing = async ({
8 cancellationToken,
9 projectPathname,
10 bundleIntoRelativePath,
11 cache,
12 cacheRelativePath,
13 importDefaultExtension,
14 importMapRelativePath,
15 importMapForBundle,
16 importAbstractMap,
17 importFallbackMap,
18 nativeModulePredicate,
19 entryPointMap,
20 babelPluginMap,
21 convertMap,
22 minify,
23 logLevel,
24 format,
25 formatOutputOptions,
26 writeOnFileSystem,
27}) => {
28 const logger = createLogger({ logLevel })
29
30 const dir = pathnameToOperatingSystemPath(`${projectPathname}${bundleIntoRelativePath}`)
31
32 const { jsenvRollupPlugin, getArrayOfAbstractHref } = await createJsenvRollupPlugin({
33 cancellationToken,
34 projectPathname,
35 bundleIntoRelativePath,
36 cache,
37 cacheRelativePath,
38 entryPointMap,
39 importDefaultExtension,
40 importMapRelativePath,
41 importMapForBundle,
42 importAbstractMap,
43 importFallbackMap,
44 babelPluginMap,
45 convertMap,
46 featureNameArray: Object.keys(babelPluginMap),
47 minify,
48 format,
49 logger,
50 })
51
52 logger.trace(`
53bundle entry points without balancing.
54format: ${format}
55entry point names: ${Object.keys(entryPointMap)}
56dir: ${dir}
57minify: ${minify}
58`)
59
60 const rollupBundle = await generateBundleUsingRollup({
61 cancellationToken,
62 writeOnFileSystem,
63 rollupParseOptions: {
64 input: entryPointMap,
65 plugins: [jsenvRollupPlugin],
66 external: (id) => nativeModulePredicate(id),
67 },
68 rollupGenerateOptions: {
69 // https://rollupjs.org/guide/en#output-dir
70 dir,
71 // https://rollupjs.org/guide/en#output-format
72 format: formatToRollupFormat(format),
73 // entryFileNames: `./[name].js`,
74 // https://rollupjs.org/guide/en#output-sourcemap
75 sourcemap: true,
76 // we could exclude them
77 // but it's better to put them directly
78 // in case source files are not reachable
79 // for whatever reason
80 sourcemapExcludeSources: false,
81 ...formatOutputOptions,
82 },
83 })
84
85 return { rollupBundle, arrayOfAbstractHref: getArrayOfAbstractHref() }
86}