-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
55 lines (53 loc) · 1.27 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
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import alias from '@rollup/plugin-alias'
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'
// 获取当前文件的目录
const __dirname = path.dirname(fileURLToPath(import.meta.url))
export default {
input: 'src/index.ts',
output: [
{
file: 'dist/index.js',
format: 'cjs',
sourcemap: false,
},
],
plugins: [
alias({
entries: [
{ find: '@', replacement: path.resolve(__dirname, 'src') },
],
}),
// 解析模块路径
resolve({
preferBuiltins: true,
extensions: ['.ts', '.js'],
}),
// 将 CommonJS 转换为 ES6 模块
commonjs(),
// 支持导入 JSON 文件
json(),
// babel
babel({
babelHelpers: 'bundled',
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
targets: {
node: '16.0',
},
useBuiltIns: 'usage',
corejs: '3.40.0',
},
],
], // 处理 TypeScript 和 ES6+ 语法
extensions: ['.ts'], // 支持的文件扩展名
}),
],
}