forked from kool-kool/kool-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
75 lines (74 loc) · 1.71 KB
/
rollup.config.mjs
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
import babel from '@rollup/plugin-babel'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import svgr from '@svgr/rollup'
import cssnano from 'cssnano'
import dts from 'rollup-plugin-dts'
import postcss from 'rollup-plugin-postcss'
import { terser } from 'rollup-plugin-terser'
import typescript from 'rollup-plugin-typescript2'
export default [
{
// 项目入口
input: 'src/index.ts',
output: [
{
// 输出文件
file: 'dist/index.es.js',
// 输出格式
format: 'esm'
},
{
file: 'dist/index.cjs.js',
format: 'cjs'
}
],
plugins: [
// 解决node 包的导入
resolve(),
// 解决commmnjs 包的导入
commonjs(),
// 导入json
json(),
// 解决svg的引入
svgr({ exportType: 'named' }),
// 编译ts
typescript({
tsconfigOverride: {
// 过滤
exclude: ['**/__test__', '.dumi/', '**/demo']
}
}),
babel({
presets: ['@babel/preset-env'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
exclude: '**/node_modules/**',
babelHelpers: 'bundled'
}),
// 处理css
postcss({
// 抽离成单独的css文件
extract: 'index.css',
plugins: [
// css压缩
cssnano()
]
}),
// 代码压缩
terser()
],
// 剔除依赖
external: ['react', 'react-dom']
},
// 生成类型声明文件
{
input: 'src/index.ts',
output: {
file: 'dist/index.d.ts',
format: 'esm'
},
plugins: [dts()],
external: [/\.scss$/]
}
]