forked from rollup/rollup
/
assignChunkIds.ts
36 lines (34 loc) · 1.14 KB
/
assignChunkIds.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
import Chunk from '../Chunk';
import { InputOptions, OutputBundleWithPlaceholders, OutputOptions } from '../rollup/types';
import { Addons } from './addons';
import { FILE_PLACEHOLDER } from './FileEmitter';
import { basename } from './path';
export function assignChunkIds(
chunks: Chunk[],
inputOptions: InputOptions,
outputOptions: OutputOptions,
inputBase: string,
addons: Addons,
bundle: OutputBundleWithPlaceholders
) {
const entryChunks: Chunk[] = [];
const otherChunks: Chunk[] = [];
for (const chunk of chunks) {
(chunk.facadeModule && chunk.facadeModule.isUserDefinedEntryPoint
? entryChunks
: otherChunks
).push(chunk);
}
// make sure entry chunk names take precedence with regard to deconflicting
const chunksForNaming: Chunk[] = entryChunks.concat(otherChunks);
for (const chunk of chunksForNaming) {
if (outputOptions.file) {
chunk.id = basename(outputOptions.file);
} else if (inputOptions.preserveModules) {
chunk.id = chunk.generateIdPreserveModules(inputBase, outputOptions, bundle);
} else {
chunk.id = chunk.generateId(addons, outputOptions, bundle, true);
}
bundle[chunk.id] = FILE_PLACEHOLDER;
}
}