-
Notifications
You must be signed in to change notification settings - Fork 4
/
rollup.base.config.js
41 lines (37 loc) · 1.14 KB
/
rollup.base.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
import fs from 'node:fs';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import typescript from '@rollup/plugin-typescript';
import { babel } from '@rollup/plugin-babel';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
const version = process.env.VERSION ?? packageJson?.version;
export default (outDir, declaration = false, minify = false) => {
const plugins = [
json(),
commonjs(),
nodeResolve({ preferBuiltins: true }),
typescript({
tsconfig: './tsconfig.json',
outDir,
declaration,
declarationDir: declaration ? `${outDir}/types` : null,
include: ['src/**/*.ts', 'schemas/*.json'],
}),
babel({
babelHelpers: 'bundled',
presets: ['@babel/preset-env'],
exclude: 'node_modules/**',
}),
replace({
preventAssignment: true,
'process.env.VERSION': JSON.stringify(version),
}),
];
if (minify) {
plugins.push(terser());
}
return { plugins };
};