-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
89 lines (84 loc) · 1.8 KB
/
rollup.config.js
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
import typescript from 'rollup-plugin-typescript2';
import babel from '@rollup/plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import json from '@rollup/plugin-json';
import { readFileSync } from 'fs';
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
import terser from '@rollup/plugin-terser';
import merge from 'lodash.merge';
import path from 'path';
const pkg = JSON.parse(
readFileSync(new URL('./package.json', import.meta.url), 'utf8')
);
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(fileURLToPath(import.meta.url));
const extensions = ['.js', '.ts'];
const pathResolve = function (...args) {
return path.resolve(__dirname, ...args);
};
// 打包任务的个性化配置
const jobs = {
esm: {
output: {
format: 'esm',
file: pathResolve(pkg.module)
}
},
cjs: {
output: {
format: 'cjs',
file: pathResolve('dist/index.cjs.js')
}
},
umd: {
output: {
format: 'umd',
file: pathResolve(pkg.main)
}
},
min: {
output: {
format: 'umd',
file: pathResolve(pkg.main.replace(/(.\w+)$/, '.min$1'))
},
plugins: [
terser({
compress: true,
mangle: true
})
]
}
};
const mergeConfig = jobs[process.env.NODE_ENV || 'esm'];
export default merge(
{
input: 'src/index.ts',
output: {
file: 'dist/tti.js',
format: 'esm',
name: 'tti'
},
plugins: [
json(),
resolve({
extensions,
modulesOnly: true
}),
typescript({
useTsconfigDeclarationDir: false,
tsconfig: 'tsconfig.json',
tsconfigOverride: {
compilerOptions: { declarationDir: 'dist/types', outDir: 'dist', declaration: true }
},
exclude: ['test/**', 'node_modules/**']
}),
babel({
exclude: 'node_modules/**',
extensions,
babelHelpers: 'bundled'
})
]
},
mergeConfig
);