-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
95 lines (86 loc) · 2.21 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import json from "@rollup/plugin-json";
import resolve from "@rollup/plugin-node-resolve";
import babel from "@rollup/plugin-babel";
import fs from 'fs';
import { modules } from './config/modules.config.mjs';
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
const { version: LIB_VERSION, description: LIB_DESCRIPTION } = pkg;
const LIB_NAME = `AJS`;
const AUTHOR_NAME = `qddegtya`;
// 生成主包的 banner
const createMainBanner = () => ({
banner: `/** ${LIB_NAME} (${LIB_VERSION}): ${LIB_DESCRIPTION} */`,
footer: `/** Follow me: @${AUTHOR_NAME} (https://github.com/${AUTHOR_NAME}) */`,
});
// 生成子模块的 banner
const createModuleBanner = (moduleName) => ({
banner: `/** ${LIB_NAME}.${moduleName} (${LIB_VERSION}): ${LIB_DESCRIPTION} */`,
footer: `/** Follow me: @${AUTHOR_NAME} (https://github.com/${AUTHOR_NAME}) */`,
});
const basePlugins = [
json({
preferConst: true,
compact: true,
namedExports: true
}),
resolve(),
babel({
babelHelpers: 'bundled'
})
];
// 主包配置
const mainConfig = {
input: "./src/index.js",
output: [
{
...createMainBanner(),
name: LIB_NAME,
file: "dist/ajs.cjs.js",
format: "cjs",
},
{
...createMainBanner(),
name: LIB_NAME,
file: "dist/ajs.umd.js",
format: "umd",
},
{
...createMainBanner(),
name: LIB_NAME,
file: "dist/ajs.es.js",
format: "es",
},
],
plugins: basePlugins,
};
// 子模块配置
const moduleConfigs = modules.map(mod => ({
input: `./src/${mod}/index.js`,
output: [
{
...createModuleBanner(mod),
file: `dist/${mod}/${mod}.es.js`,
format: 'es',
},
{
...createModuleBanner(mod),
file: `dist/${mod}/${mod}.cjs.js`,
format: 'cjs',
},
{
...createModuleBanner(mod),
file: `dist/${mod}/${mod}.umd.js`,
format: 'umd',
name: `${LIB_NAME}_${mod.toUpperCase()}`
}
],
plugins: basePlugins,
// 外部依赖处理
external: [
// 将其他模块标记为外部依赖
...modules.filter(m => m !== mod).map(m => `xajs/${m}`),
// 添加其他可能的外部依赖
/^@babel\/runtime/
]
}));
export default [mainConfig, ...moduleConfigs];