-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrolldown.config.mjs
More file actions
101 lines (93 loc) · 2.37 KB
/
Copy pathrolldown.config.mjs
File metadata and controls
101 lines (93 loc) · 2.37 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { builtinModules, createRequire } from 'node:module';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'rolldown';
import { dts } from 'rolldown-plugin-dts';
const require = createRequire(import.meta.url);
const rootDir = dirname(fileURLToPath(import.meta.url));
const packageDir = resolve(process.env.COACTION_PACKAGE_DIR ?? process.cwd());
const packageJson = require(join(packageDir, 'package.json'));
const input = join(packageDir, 'index.ts');
const distDir = join(packageDir, 'dist');
const dependencies = new Set([
...Object.keys(packageJson.dependencies ?? {}),
...Object.keys(packageJson.peerDependencies ?? {}),
...Object.keys(packageJson.optionalDependencies ?? {})
]);
const builtins = new Set([
...builtinModules,
...builtinModules.map((name) => `node:${name}`)
]);
const isExternal = (id) => {
if (builtins.has(id)) {
return true;
}
for (const dependency of dependencies) {
if (id === dependency || id.startsWith(`${dependency}/`)) {
return true;
}
}
return false;
};
const dtsCompilerOptions = {
target: 'ESNext',
module: 'ESNext',
moduleResolution: 'Bundler',
jsx: 'react-jsx',
strict: true,
skipLibCheck: true,
stripInternal: true,
resolveJsonModule: true,
allowImportingTsExtensions: true,
lib: ['ES2019', 'ESNext.Promise', 'DOM'],
baseUrl: rootDir,
rootDir: packageDir,
paths: {
coaction: ['packages/core/index.ts']
}
};
export default defineConfig([
{
input,
external: isExternal,
platform: 'neutral',
treeshake: true,
tsconfig: join(rootDir, 'tsconfig.json'),
output: [
{
file: join(distDir, 'index.mjs'),
format: 'esm',
codeSplitting: false,
sourcemap: false
},
{
file: join(distDir, 'index.js'),
format: 'cjs',
exports: 'named',
codeSplitting: false,
sourcemap: false
}
]
},
{
input,
external: isExternal,
platform: 'neutral',
treeshake: true,
plugins: [
dts({
cwd: rootDir,
tsconfig: join(rootDir, 'tsconfig.json'),
compilerOptions: dtsCompilerOptions,
emitDtsOnly: true
})
],
output: {
dir: distDir,
entryFileNames: 'index.d.ts',
chunkFileNames: '[name].d.ts',
format: 'esm',
sourcemap: false
}
}
]);