-
Notifications
You must be signed in to change notification settings - Fork 13
/
rollup.config.js
119 lines (110 loc) · 3.97 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
import resolve from "@rollup/plugin-node-resolve";
import babel from "@rollup/plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import replace from "rollup-plugin-replace";
import typescript from "rollup-plugin-typescript2";
/* Rollup outputs module and main bundles for the @nulogy/components package */
import packageJson from "./package.json";
const PEER_DEPENDENCIES = {
react: "React",
"styled-components": "styled",
"@nulogy/icons": "icons",
};
const GLOBALS = {
...PEER_DEPENDENCIES,
"react-windowed-select": "components",
"@babel/runtime/helpers/typeof": "typeof",
"@babel/runtime/helpers/defineProperty": "defineProperty",
"@babel/runtime/helpers/classCallCheck": "classCallCheck",
"@babel/runtime/helpers/createClass": "createClass",
"@babel/runtime/helpers/slicedToArray": "slicedToArray",
"@babel/runtime/helpers/objectWithoutProperties": "objectWithoutProperties",
"object-assign": "assign",
"@babel/runtime/helpers/objectWithoutPropertiesLoose": "objectWithoutPropertiesLoose",
"@babel/runtime/helpers/extends": "extends",
"@babel/runtime/helpers/assertThisInitialized": "assertThisInitialized",
"@babel/runtime/helpers/inheritsLoose": "inheritsLoose",
"deep-equal": "deepEqual",
"create-react-context": "createReactContext",
warning: "warning",
exenv: "exenv",
classnames: "t",
"html-parse-stringify2": "HTML",
"smoothscroll-polyfill": "smoothscroll",
"react-fast-compare": "isEqual",
"path-to-regexp": "pathToRegexp",
"react-is": "reactIs",
"react-dom": "reactDom",
};
const externals = Object.keys(GLOBALS);
const EXTENSIONS = [".js", ".jsx", "ts", ".tsx", ".mjs"];
const CORE_PLUGINS = [
/* typescript: see tsconfig.json for settings */
typescript(),
/* commonJS: convert CommonJS modules to ES6,
so they can be included in a Rollup bundle */
commonjs({
/* include: include all items in node_modules folders (in entire monorepo) */
include: [/node_modules/],
/* namedExports: sometimes commonjs can't resolve named exports from certain libraries,
ex: import {exportName} from "package-name"; => exportName module not found
in those cases, it needs to be added as ["package-name"]: "exportName" here */
namedExports: {
debounce: ["debounce"],
"react-windowed-select": ["components"],
},
}),
/* babel: transiles the bundle according to babel.config */
babel({
/* babelHelpers: runtime tells babel to import from @babel/runtime instead of duplicated them */
babelHelpers: "runtime",
/* exclude: globs to exclude */
exclude: ["./node_modules/**/*"],
/* exclude: files to be transpiled by babel */
extensions: EXTENSIONS,
}),
/* replace: replaces strings when bundling */
replace({
exclude: /node_modules/,
/* ENV is replaced by environment setting */
ENV: JSON.stringify(process.env.NODE_ENV || "development"),
}),
];
const ENTRY_FILE = "src/index.ts";
const mainBundles = {
/* input: main export file */
input: ENTRY_FILE,
/* external: external dependencies, all peerDependencies */
external: externals,
output: [
// UMD format for compatibility with most script loaders
{
file: packageJson.main,
name: "NDSComponents",
format: "umd",
// globals: global variable names of external dependencies
globals: GLOBALS,
},
// ES module format for package.module field, auto-imports and optimal tree-shaking
{
file: packageJson.module,
format: "es",
globals: GLOBALS,
},
],
plugins: [
// resolve: resolves node_modules imports
resolve({
/* mainFields: specifies the which package fields to look for first
package.module and then if it's not specified look at
package.main */
mainFields: ["module", "main"],
/* modulesOnly: inspect resolved files are es2015 modules */
modulesOnly: true,
/* extensions: specifies the file extensions to accept as imports */
extensions: EXTENSIONS,
}),
...CORE_PLUGINS,
],
};
export default [mainBundles];