-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
71 lines (65 loc) · 1.94 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
import commonjs from "rollup-plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import nodeResolve, { DEFAULTS } from "@rollup/plugin-node-resolve";
import sourcemaps from "rollup-plugin-sourcemaps";
import { terser } from "rollup-plugin-terser";
import babel from "@rollup/plugin-babel";
import json from "@rollup/plugin-json";
import filesize from "rollup-plugin-filesize";
import dts from "rollup-plugin-dts";
import pkg from "./package.json" assert { type: "json" };
// eslint-disable-next-line no-undef
const BUILD_TARGET_ENV = process.env.TARGET;
const isDev = BUILD_TARGET_ENV === "dev";
const buildOutputDir = isDev ? "./playground/" : "./dist/";
/**
* sourceMap is true by default, but we want to disable it for production builds
*/
const sourcemap = !isDev;
/**
* We want to use the same extensions as the node-resolve plugin
*/
const extensions = [...DEFAULTS.extensions, ".ts", ".tsx"];
const bundleConfig = {
input: "lib/index.ts",
output: [
{
sourcemap: sourcemap,
file: buildOutputDir + pkg.exports.default,
format: "umd",
name: "RuleEngine",
exports: "named",
},
{ sourcemap: sourcemap, format: "esm", file: buildOutputDir + pkg.exports.import },
{
sourcemap: sourcemap,
format: "cjs",
file: buildOutputDir + pkg.exports.require,
exports: "named",
},
],
plugins: [
commonjs(),
typescript(),
nodeResolve({ extensions, moduleDirectories: ["node_modules"] }),
json(),
sourcemaps(),
filesize(),
terser(),
babel({ exclude: "node_modules/**", extensions, babelHelpers: "runtime" }),
],
external: [...Object.keys(pkg.peerDependencies || {}), /@babel\/runtime/],
watch: {
include: "lib/**",
},
};
const dtsConfig = {
input: "lib/index.ts",
output: [{ file: "./dist/index.d.ts", format: "es" }],
plugins: [dts()],
};
const configs = [bundleConfig];
if (!isDev) {
configs.push(dtsConfig);
}
export default configs;