-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.mjs
91 lines (85 loc) · 2.11 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
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',
}),
babel({
extensions: ['.ts', '.js'],
babelHelpers: 'bundled',
}),
];
/**
* disallow circular deps
* @see https://rollupjs.org/configuration-options/#onwarn
* @param {*} warning
* @param {*} warn
*/
function onwarn(warning, warn) {
if (warning.code === 'CIRCULAR_DEPENDENCY') {
console.error(chalk.redBright(warning.message));
throw Object.assign(new Error(), warning);
}
warn(warning);
}
// https://rollupjs.org/guide/en/#configuration-files
export default [
{
input: process.env.BUILD_INPUT?.split(splitter) || ['./index.ts'],
output: [
{
file: path.resolve(dirname, `${basename}.mjs`),
name: 'fabric',
format: 'es',
sourcemap: true,
},
{
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',
plugins: [terser()],
}
: null,
],
plugins,
onwarn,
},
{
input: ['./index.node.ts'],
output: [
{
file: path.resolve(dirname, `${basename}.node.mjs`),
name: 'fabric',
format: 'es',
sourcemap: true,
},
{
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'],
},
];