forked from udecode/plate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
122 lines (108 loc) · 3.12 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
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 external from 'rollup-plugin-peer-deps-external';
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 = [
// Automatically externalize peerDependencies
external(),
// Let you use relative paths in your import directives
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(),
// 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',
name: PKG_JSON.name,
sourcemap: true,
},
// ES module (for bundlers)
{
file: PKG_JSON.module,
format: 'es',
name: PKG_JSON.name,
sourcemap: true,
},
],
plugins,
},
];