-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.js
More file actions
69 lines (63 loc) · 1.71 KB
/
rollup.config.js
File metadata and controls
69 lines (63 loc) · 1.71 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
import fs from 'node:fs/promises'
import replace from '@rollup/plugin-replace'
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript'
import dts from 'rollup-plugin-dts'
const PACKAGE_NAME = 'vue-reactive-reactive'
// 生成 CJS 入口文件的函数
async function generateCJSEntry() {
const template = await fs.readFile('./scripts/cjs-entry-template.js', 'utf-8')
await fs.mkdir('./dist', { recursive: true })
await fs.writeFile('./dist/index.js', template)
}
function createConfig(isProduction) {
return {
input: './src/index.ts',
external: ['@vue/reactivity'],
plugins: [
replace({
'preventAssignment': true,
'__DEV__': !isProduction,
'process.env.NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development'),
}),
typescript({
tsconfig: './tsconfig.lib.json',
}),
isProduction && terser(),
].filter(Boolean),
output: [
{
format: 'cjs',
file: `./dist/${PACKAGE_NAME}${isProduction ? '.production' : '.development'}.cjs`,
sourcemap: true,
},
{
format: 'esm',
file: `./dist/${PACKAGE_NAME}${isProduction ? '.production' : '.development'}.mjs`,
sourcemap: true,
},
],
}
}
// Types bundle configuration
const dtsConfig = {
input: './src/index.ts',
external: ['@vue/reactivity'],
plugins: [
dts({
compilerOptions: {
preserveSymlinks: false,
},
}),
],
output: {
format: 'esm',
file: `./dist/${PACKAGE_NAME}.d.ts`,
},
}
generateCJSEntry().catch(console.error)
export default [
createConfig(false), // Development build
createConfig(true), // Production build
dtsConfig, // Types
]