-
Notifications
You must be signed in to change notification settings - Fork 5
/
rollup.config.js
94 lines (82 loc) · 2.46 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
"use strict";
import { readFileSync, writeFileSync } from "fs";
import { join } from "path";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import terser from "@rollup/plugin-terser";
const pkg = JSON.parse(readFileSync("./package.json"));
const banner = `/*! ${pkg.name}@${pkg.version} !*/\n`;
// Plugin for making stub package.json files that tell the type of the modules in the folder
// Resources:
// https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html
// https://2ality.com/2019/10/hybrid-npm-packages.html
// https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1
//
const stubby = (type) => ({
name : `stubby-${type}`,
writeBundle({ dir },) {
writeFileSync(join(dir, "package.json"), JSON.stringify({ type }, null, 4));
},
});
const cjsStub = stubby("commonjs");
const esmStub = stubby("module");
export default [{
input : {
"xstate-component-tree" : "./src/index.js",
},
plugins : [
nodeResolve(),
commonjs(),
],
output : [{
dir : "./dist/cjs",
format : "cjs",
exports : "named",
sourcemap : true,
banner,
plugins : [
cjsStub,
],
}, {
dir : "./dist/cjs",
entryFileNames : "[name]-min.js",
format : "cjs",
exports : "named",
sourcemap : true,
plugins : [
terser(),
cjsStub,
],
banner,
}, {
dir : "./dist/esm",
format : "es",
sourcemap : true,
banner,
plugins : [
esmStub,
],
}, {
dir : "./dist/esm",
entryFileNames : "[name]-min.js",
format : "es",
sourcemap : true,
plugins : [
terser({
mangle : {
// Keep classnames intact for more usable stack traces
keep_classnames : true,
// Mangle properties
properties : {
// Except teardown because that's part of the public API
reserved : [
"teardown",
],
},
},
}),
esmStub,
],
banner,
}],
}];