-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
82 lines (79 loc) · 2.14 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
import Module from "module";
import path from "path";
import graphql from "@kocal/rollup-plugin-graphql";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import babel from "rollup-plugin-babel";
import { terser } from "rollup-plugin-terser";
import pkg from "./package.json";
const WATCH = Boolean(process.env.ROLLUP_WATCH);
const EXTENSIONS = [".mjs", ".js", ".json", ".ts"];
const OUTPUT_DIR = "dist";
const OUTPUT_DIR_NODE = path.join(OUTPUT_DIR, "node");
const OUTPUT_DIR_BROWSER = path.join(OUTPUT_DIR, "browser");
const ENVS = {
"process.env.NODE_ENV": JSON.stringify("development")
};
const getPlugins = ({ target }) => {
return [
replace(ENVS),
resolve({
extensions: EXTENSIONS,
browser: target === "browser" ? true : false
}),
commonjs({
namedExports: {}
}),
babel({
extensions: EXTENSIONS,
// Will be merged with `babel.config.js`
presets: [
target === "browser"
? [
"@babel/preset-env",
{
targets:
">0.25%, not dead, ie 11, not op_mini all, not android <= 4.4, not samsung <= 4",
modules: false,
useBuiltIns: "usage",
corejs: {
version: 3,
proposals: true
}
}
]
: [
"@babel/preset-env",
{
targets: { node: "10" },
modules: false
}
]
]
}),
graphql(),
!WATCH && target === "browser" && terser()
];
};
export default [
{
input: "src/index.ts",
output: {
file: path.join(OUTPUT_DIR_NODE, "index.js"),
format: "cjs",
sourcemap: true
},
external: [...Module.builtinModules, ...Object.keys(pkg.dependencies)],
plugins: getPlugins({ target: "node" })
},
{
input: "src/index.ts",
output: {
file: path.join(OUTPUT_DIR_BROWSER, "index.js"),
format: "esm",
sourcemap: true
},
plugins: getPlugins({ target: "browser" })
}
];