-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
97 lines (92 loc) · 2.73 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
97
import nodeResolve from '@rollup/plugin-node-resolve';
import typescript from "rollup-plugin-typescript2";
import replace from "@rollup/plugin-replace";
import json from '@rollup/plugin-json';
import commonjs from "@rollup/plugin-commonjs";
import terser from '@rollup/plugin-terser';
import * as path from 'node:path';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dts } from "rollup-plugin-dts";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), { encoding: "utf8" }));
const masterVersion = pkg.version;
const tsconfigFile = path.join(__dirname, 'tsconfig.json');
const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.devDependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
];
function createPlugins() {
const replaceValues = {
__VERSION__: `${masterVersion}`,
__BUILD_DATE__: `${Date.now()}`,
__AUTHOR__: 'ywx1818@163.com'
};
const tsPlugin = typescript({
clean: true,
tsconfig: tsconfigFile,
cacheRoot: path.resolve(__dirname, 'node_modules/.rts2_cache')
});
const plugins = [
json({ namedExports: false }),
tsPlugin,
replace({
preventAssignment: true,
values: replaceValues
}),
nodeResolve(),
commonjs(),
];
if (typeof process !== 'undefined' && process.env.BUILD === 'production') {
plugins.push(terser({
module: true,
compress: {
ecma: 2015,
pure_getters: true
},
safari10: true,
maxWorkers: 4
}));
}
return plugins;
}
function getDtsConfig() {
const input = path.join(__dirname, 'src/main.ts');
const plugins = [dts()];
const output = [{
file: path.join(__dirname, `dist/index.d.ts`),
format: 'es'
}];
return {input, plugins, output};
}
export default async (args) => {
return [
{
input: {
index: './src/main.ts',
},
output: {
exports: 'named',
sourcemap: true,
freeze: false,
format: 'es',
externalLiveBindings: false,
dir: 'dist',
entryFileNames: `[name].es.js`
},
external,
onwarn: (msg, warn) => {
if (!/Circular/.test(msg)) {
warn(msg)
}
},
treeshake: {
moduleSideEffects: false
},
plugins: createPlugins()
},
getDtsConfig()
];
};