-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
rollup.config.mjs
180 lines (173 loc) · 4.32 KB
/
rollup.config.mjs
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import json from '@rollup/plugin-json';
import terser from '@rollup/plugin-terser';
import ts from '@rollup/plugin-typescript';
import { babel } from '@rollup/plugin-babel';
import path from 'path';
import chalk from 'chalk';
// import dts from "rollup-plugin-dts";
const splitter = /\n|\s|,/g;
const buildOutput = process.env.BUILD_OUTPUT || './dist/index.js';
const dirname = path.dirname(buildOutput);
const basename = path.basename(buildOutput, '.js');
const plugins = [
json(),
ts({
noForceEmit: true,
tsconfig: './tsconfig.json',
exclude: ['dist', 'dist-extensions', '**/**.spec.ts', '**/**.test.ts'],
}),
babel({
extensions: ['.ts', '.js'],
babelHelpers: 'bundled',
}),
];
const pluginsExtensions = [
json(),
ts({
noForceEmit: true,
tsconfig: './tsconfig-extensions.json',
exclude: ['dist', 'dist-extensions', '**/**.spec.ts', '**/**.test.ts'],
}),
babel({
extensions: ['.ts', '.js'],
babelHelpers: 'bundled',
}),
];
/**
* disallow circular deps
* @see https://rollupjs.org/configuration-options/#onwarn
* @param {*} warning
* @param {*} warn
*/
function onwarn(warning, warn) {
// we error at any warning.
// we allow-list the errors we understand are not harmful
if (
(warning.code === 'PLUGIN_WARNING' &&
!warning.message.includes('sourcemap')) ||
warning.code === 'CIRCULAR_DEPENDENCY'
) {
console.error(chalk.redBright(warning));
if (process.env.CI) {
throw Object.assign(new Error(), warning);
}
}
warn(warning);
}
// https://rollupjs.org/guide/en/#configuration-files
export default [
{
input: ['./fabric.ts'],
output: [
// es modules in files
{
dir: path.resolve(dirname),
format: 'es',
preserveModules: true,
entryFileNames: '[name].mjs',
sourcemap: true,
},
Number(process.env.MINIFY)
? {
dir: path.resolve(dirname),
format: 'es',
preserveModules: true,
entryFileNames: '[name].min.mjs',
sourcemap: true,
plugins: [terser()],
}
: null,
],
plugins,
onwarn,
},
{
input: process.env.BUILD_INPUT?.split(splitter) || ['./index.ts'],
output: [
// es module in bundle
{
file: path.resolve(dirname, `${basename}.mjs`),
name: 'fabric',
format: 'es',
sourcemap: true,
},
Number(process.env.MINIFY)
? {
file: path.resolve(dirname, `${basename}.min.mjs`),
name: 'fabric',
format: 'es',
sourcemap: true,
plugins: [terser()],
}
: null,
// umd module in bundle, the cdn one for fiddles
// deprecated, this will be available only minified for cdn.
{
file: path.resolve(dirname, `${basename}.js`),
name: 'fabric',
format: 'umd',
sourcemap: true,
},
Number(process.env.MINIFY)
? {
file: path.resolve(dirname, `${basename}.min.js`),
name: 'fabric',
format: 'umd',
sourcemap: true,
plugins: [terser()],
}
: null,
],
plugins,
onwarn,
},
{
input: ['./index.node.ts'],
output: [
{
file: path.resolve(dirname, `${basename}.node.mjs`),
name: 'fabric',
format: 'es',
sourcemap: true,
},
// deprecated remove
{
file: path.resolve(dirname, `${basename}.node.cjs`),
name: 'fabric',
format: 'cjs',
sourcemap: true,
},
],
plugins,
onwarn,
external: ['jsdom', 'jsdom/lib/jsdom/living/generated/utils.js', 'canvas'],
},
// EXTENSIONS
{
input: ['./extensions/index.ts'],
external: ['fabric'],
output: [
// es modules in files
{
dir: path.resolve('./dist-extensions'),
format: 'es',
preserveModules: true,
entryFileNames: '[name].mjs',
sourcemap: true,
},
// umd module, the cdn one for fiddles, minified
{
file: path.resolve('./dist-extensions', `fabric-extensions.min.js`),
name: 'fabricExtensions',
format: 'umd',
sourcemap: true,
globals: {
fabric: 'fabric',
},
plugins: [terser()],
},
],
plugins: pluginsExtensions,
onwarn,
},
];