-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
96 lines (91 loc) · 2.47 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
90
91
92
93
94
95
96
/**
* rollup.config.js
* @type {import('rollup').RollupOptions}
* @see https://cn.rollupjs.org/configuration-options
* sobird<[email protected]> at 2023/09/28 11:30:37 created.
*/
import { defineConfig } from 'rollup';
import { glob } from 'glob';
import { dirname, relative, extname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import external from 'rollup-plugin-peer-deps-external';
import typescript from 'rollup-plugin-typescript2';
import terser from '@rollup/plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import copy from 'rollup-plugin-copy';
import clear from 'rollup-plugin-clear';
// import mdx from '@mdx-js/rollup';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const isProduction = process.env.NODE_ENV === 'production';
const DIST = isProduction ? 'dist' : 'dist';
function input(pattern) {
return glob.sync(pattern, {
ignore: ['src/**/*.d.ts'],
cwd: __dirname,
absolute: false,
}).reduce((accu, filename) => {
accu[relative(
'src',
filename.slice(0, filename.length - extname(filename).length),
)] = filename;
return accu;
}, {});
}
const mainInput = input(['src/**/*.{ts,js}']);
export default (env) => {
return defineConfig([
// { // es module
// input: mainInput,
// output: {
// //preserveModules: true,
// dir: `${DIST}/es`,
// format: "es",
// },
// plugins: plugins({
// clear: {
// targets: [`${DIST}/es`],
// },
// }, env),
// },
{ // cjs module
input: mainInput,
output: {
dir: `${DIST}`,
format: 'es',
},
plugins: [
clear({
targets: [DIST],
watch: false,
}),
external({
includeDependencies: true,
}),
nodeResolve({
preferBuiltins: true,
}),
commonjs(),
typescript({
check: false,
// declaration: true,
// tsconfig: "./src/tsconfig.json",
// noEmitOnError: false,
strictRequires: true,
}),
terser(),
json(),
copy({
targets: [
{ src: 'package.json', dest: DIST },
{ src: 'README.md', dest: DIST },
{ src: 'LICENSE', dest: DIST },
],
copyOnce: env.watch,
}),
],
},
]);
};