-
-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathrolldown.common.config.js
More file actions
72 lines (69 loc) · 2.13 KB
/
rolldown.common.config.js
File metadata and controls
72 lines (69 loc) · 2.13 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { defineConfig } from 'rolldown';
import { dts } from 'rolldown-plugin-dts';
import { replacePlugin } from 'rolldown/plugins';
const inputDir = 'src';
const outputDir = 'lib';
export default function buildConfigFor(pkg, dirname, replacementsFor) {
let isDual = false;
const inputs = Object.values(pkg.exports)
.map((exportValue) => {
if (typeof exportValue === 'string') {
return exportValue;
}
isDual = true;
return exportValue.import.default;
})
.filter((filePath) => filePath.endsWith('.js'))
.map((filePath) => filePath.replace(`./${outputDir}/`, `./${inputDir}/`));
/** @type {RolldownOptions} */
const sharedOptions = {
input: inputs,
output: {
cleanDir: true,
dir: outputDir,
format: 'esm',
entryFileNames: (chunkInfo) => {
const cwdAndInputDirLength = dirname.length + inputDir.length + 2;
const relativeFilePathWithTsExtension = chunkInfo.facadeModuleId.substring(cwdAndInputDirLength);
return `${relativeFilePathWithTsExtension.replace(/\.ts$/, '')}.js`;
},
},
external: /^[^./]/, // as recommended by https://rolldown.rs/reference/InputOptions.external#avoid-node-modules-for-npm-packages
treeshake: {
moduleSideEffects: false,
},
plugins: [],
};
return defineConfig([
{
...sharedOptions,
output: {
...sharedOptions.output,
format: 'esm',
},
plugins: [
...sharedOptions.plugins,
...(replacementsFor !== undefined ? [replacePlugin(replacementsFor(true), { preventAssignment: true })] : []),
dts({ tsconfig: './tsconfig.publish.types.json' }),
],
},
...(isDual
? [
{
...sharedOptions,
output: {
...sharedOptions.output,
format: 'cjs',
dir: outputDir + '/cjs',
},
plugins: [
...sharedOptions.plugins,
...(replacementsFor !== undefined
? [replacePlugin(replacementsFor(false), { preventAssignment: true })]
: []),
],
},
]
: []),
]);
}