forked from udecode/plate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
135 lines (122 loc) · 3.38 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
132
133
134
135
import path from 'path';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import includePaths from 'rollup-plugin-includepaths';
import json from 'rollup-plugin-json';
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import resolve from 'rollup-plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
const PACKAGE_ROOT_PATH = process.cwd();
const INPUT_FILE = path.join(PACKAGE_ROOT_PATH, 'src/index.ts');
const PKG_JSON = require(path.join(PACKAGE_ROOT_PATH, 'package.json'));
const isUmd = false;
const includePathOptions = {
include: {},
paths: [path.join(PACKAGE_ROOT_PATH, 'src')],
external: [],
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
};
const plugins = [
includePaths(includePathOptions),
// Allow Rollup to resolve modules from `node_modules`, since it only
// resolves local modules by default.
resolve({
browser: true,
}),
typescript({
clean: true,
tsconfig: 'tsconfig.build.json',
}),
// Allow Rollup to resolve CommonJS modules, since it only resolves ES2015
// modules by default.
commonjs({
include: 'node_modules/**',
namedExports: {
'node_modules/react/index.js': [
'cloneElement',
'createContext',
'Component',
'createElement',
],
'node_modules/react-dom/index.js': ['render', 'hydrate'],
'node_modules/react-is/index.js': [
'isElement',
'isValidElementType',
'ForwardRef',
],
},
}),
// Convert JSON imports to ES6 modules.
json(),
// Register Node.js builtins for browserify compatibility.
builtins(),
// Use Babel to transpile the result, limiting it to the source code.
babel({
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
node: 'current',
},
},
],
'@babel/preset-react',
'@babel/preset-typescript',
],
plugins: [
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
'babel-plugin-dynamic-import-node',
'babel-plugin-styled-components',
['inline-json-import', {}],
],
env: {
test: {
presets: [
['@babel/preset-react', { modules: 'commonjs' }],
['@babel/preset-env', { modules: 'commonjs' }],
],
},
},
extensions: ['.js', '.jsx', '.es6', '.es', '.mjs', '.ts', '.tsx'],
exclude: 'node_modules/**',
runtimeHelpers: true,
}),
// Register Node.js globals for browserify compatibility.
globals(),
// Only minify the output in production, since it is very slow. And only
// for UMD builds, since modules will be bundled by the consumer.
isUmd && terser(),
];
export default [
{
input: INPUT_FILE,
external: [
...Object.keys(PKG_JSON.dependencies || {}),
...Object.keys(PKG_JSON.peerDependencies || {}),
],
output: [
// CommonJS (for Node)
{
file: PKG_JSON.main,
format: 'cjs',
exports: 'named',
sourcemap: true,
name: PKG_JSON.name,
},
// ES module (for bundlers)
{
file: PKG_JSON.module,
format: 'es',
exports: 'named',
sourcemap: true,
name: PKG_JSON.name,
},
],
plugins,
},
];