This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
131 lines (121 loc) · 2.84 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* eslint-disable no-console */
import path from "path";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import external from "rollup-plugin-peer-deps-external";
import filesize from "rollup-plugin-filesize";
import visualizer from "rollup-plugin-visualizer";
import alias from "@rollup/plugin-alias";
import dotenv from "@gedhean/rollup-plugin-dotenv";
import json from "@rollup/plugin-json";
import nodePolyfills from "rollup-plugin-polyfill-node";
import esbuild from "rollup-plugin-esbuild";
import typescript from "rollup-plugin-typescript2";
import dtsBundle from "rollup-plugin-dts-bundle";
import pkg from "./package.json";
const isProd = process.env.NODE_ENV === "production";
console.log(`Running in ${isProd ? "Production" : "Development"}`);
const input = "src/index.ts";
const extensions = [".ts", ".js", ".json"];
const codes = [
"THIS_IS_UNDEFINED",
"MISSING_GLOBAL_NAME",
"CIRCULAR_DEPENDENCY"
];
// const minifyExtension = (pathToFile) => pathToFile.replace(/\.js$/, ".min.js");
const discardWarning = (warning) => {
if (codes.includes(warning.code)) {
return;
}
console.error(warning);
};
const plugins = [
typescript(),
dtsBundle({
bundle: {
name: pkg.name,
main: "build/src/index.d.ts",
out: "typings.d.ts"
}
// deleteOnComplete: ["build/src/**/*.d.ts"]
}),
dotenv(),
// NOTE: we've tried using rollup-plugin-inject-process-env
// however it will get an error on environments that doesn't support
// process.env reassignmment
// injectProcessEnv({
// NODE_ENV: process.env.NODE_ENV || "development",
// APP_NAME: pkg.name,
// APP_VERSION: pkg.version
// }),
esbuild({
include: /\.ts?$/,
exclude: /node_modules/,
sourceMap: !isProd,
minify: isProd,
tsconfig: "./tsconfig.json",
target: "es6",
define: {
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
"process.env.APP_NAME": JSON.stringify(pkg.name),
"process.env.APP_VERSION": JSON.stringify(pkg.version)
},
loaders: {
// Add .json files support
".json": "json"
}
}),
commonjs(),
json(),
nodePolyfills({ include: ["crypto"] }),
alias({
entries: [{ find: "@", replacement: path.resolve(__dirname, "./src") }]
}),
external(),
resolve({
browser: true,
extensions,
preferBuiltins: false
}),
filesize(),
visualizer()
];
export default [
// CommonJS (Node)
{
output: {
file: pkg.main,
format: "cjs",
exports: "named",
sourcemap: !isProd
},
plugins
},
// UMD / IIFE / Browser
{
output: {
file: pkg.browser,
format: "umd",
name: "usher",
esModule: false,
exports: "named",
sourcemap: !isProd
},
plugins
},
// ES (Import/Export)
{
output: {
file: pkg.module,
format: "es",
exports: "named",
sourcemap: !isProd
},
plugins
}
].map((conf) => ({
input,
onwarn: discardWarning,
treeshake: true,
...conf
}));