-
Notifications
You must be signed in to change notification settings - Fork 7
/
rollup.config.js
95 lines (89 loc) · 2.47 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
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import babel from "@rollup/plugin-babel";
import replace from "@rollup/plugin-replace";
import serve from "rollup-plugin-serve";
import livereload from "rollup-plugin-livereload";
import pkg from "./package.json";
import { terser } from "rollup-plugin-terser";
import react from "react";
import reactDom from "react-dom";
const production = !process.env.ROLLUP_WATCH;
const NODE_ENV = process.env.NODE_ENV || "development";
// CommonJS (for Node) and ES module (for bundlers) build.
let productionRollup = {
input: "src/main.js",
output: [
{ file: pkg.main, format: "cjs" },
{
file: pkg.main.replace(/\.js$/, ".min.js"),
format: "cjs",
plugins: [terser()],
},
{ file: pkg.module, format: "es" },
{
file: pkg.browser,
format: "umd",
name: "openSeadragonViewer",
globals: {
react: "React",
"react-dom": "ReactDOM",
"react-device-detect": "reactDeviceDetect",
"@emotion/react": "react",
"react-select": "Select",
"@reglendo/canvas2image": "Canvas2Image",
openseadragon: "OpenSeadragon",
},
},
],
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],
plugins: [
replace({
"process.env.NODE_ENV": JSON.stringify(NODE_ENV),
}),
babel({
babelHelpers: "runtime",
babelrc: true,
exclude: "node_modules/**",
}),
resolve(), // tells Rollup how to find packages in node_modules
commonjs(), // converts node_modules packages to ES modules
],
};
//browser-friendly UMD build used for development
let devRollup = {
input: "src/index.js",
output: {
name: "testRollupApp",
file: "public/bundle.js",
format: "umd",
sourcemap: true,
},
plugins: [
replace({
"process.env.NODE_ENV": JSON.stringify(NODE_ENV),
preventAssignment: true,
}),
babel({
babelHelpers: "runtime",
babelrc: true,
exclude: "node_modules/**",
}),
resolve(),
commonjs({
include: "node_modules/**",
namedExports: {
react: Object.keys(react),
"react-dom": Object.keys(reactDom),
openseadragon: ["Point"],
},
}),
// Serve the app and live reload
!production && serve({ open: true, contentBase: "public" }),
!production && livereload(),
],
};
export default production ? productionRollup : devRollup;