forked from stenciljs/core
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate-esm-browser.ts
48 lines (43 loc) · 1.58 KB
/
generate-esm-browser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { generatePreamble } from '@utils';
import type { OutputOptions, RollupBuild } from 'rollup';
import type * as d from '../../../declarations';
import { generateRollupOutput } from '../../app-core/bundle-app-core';
import { generateLazyModules } from './generate-lazy-module';
export const generateEsmBrowser = async (
config: d.ValidatedConfig,
compilerCtx: d.CompilerCtx,
buildCtx: d.BuildCtx,
rollupBuild: RollupBuild,
outputTargets: d.OutputTargetDistLazy[],
): Promise<d.UpdatedLazyBuildCtx> => {
const esmOutputs = outputTargets.filter((o) => !!o.esmDir && !!o.isBrowserBuild);
if (esmOutputs.length) {
const outputTargetType = esmOutputs[0].type;
const esmOpts: OutputOptions = {
banner: generatePreamble(config),
format: 'es',
entryFileNames: '[name].esm.js',
chunkFileNames: config.hashFileNames ? 'p-[hash].js' : '[name]-[hash].js',
assetFileNames: config.hashFileNames ? 'p-[hash][extname]' : '[name]-[hash][extname]',
sourcemap: config.sourceMap,
};
const output = await generateRollupOutput(rollupBuild, esmOpts, config, buildCtx.entryModules);
if (output != null) {
const es2017destinations = esmOutputs
.map((o) => o.esmDir)
.filter((esmDir): esmDir is string => typeof esmDir === 'string');
buildCtx.esmBrowserComponentBundle = await generateLazyModules(
config,
compilerCtx,
buildCtx,
outputTargetType,
es2017destinations,
output,
'es2017',
true,
'',
);
}
}
return { name: 'esm-browser', buildCtx };
};