-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
95 lines (88 loc) · 2.65 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
import typescript from "@rollup/plugin-typescript";
import terser from "@rollup/plugin-terser";
import fs from 'fs/promises';
// https://rollupjs.org/guide/en/#configuration-files
export default async(commandLineArgs)=>{
await fs.rm('./dist', { recursive: true, force: true });
const terser_format = {
comments: function(node, comment){
const text = comment.value;
const type = comment.type;
if (type == "comment2") {
// multiline comment
return false;
}
},
};
const plugin_terser_es6 = terser({ ecma: 6, format: terser_format });
return [
{
input: "src/index.ts",
plugins: [
typescript( { tsconfig: './tsconfig.json' })
],
output: [
// index.mjs
// for rollup/webpack to compile together with other
// or use in <script type="module">
{
file: "dist/index.mjs",
format: "es",
exports: "default",
sourcemap: true,
plugins: [
{
// index.esm.js
// for rollup/webpack to compile together with other, target browser
// same as mjs, webpack 4 don't know mjs, so current we still set esm.js as package.json->browser
// https://rollupjs.org/guide/en/#writebundle
async writeBundle(options, bundle){
await fs.copyFile('./dist/index.mjs', './dist/index.esm.js')
}
},
],
},
// index.min.mjs
{
file: "dist/index.min.mjs",
format: "es",
exports: "default",
sourcemap: true,
plugins: [
plugin_terser_es6,
{
// index.esm.js
// for rollup/webpack to compile together with other, target browser
// same as mjs, webpack 4 don't know mjs, so current we still set esm.js as package.json->browser
// https://rollupjs.org/guide/en/#writebundle
async writeBundle(options, bundle){
await fs.copyFile('./dist/index.min.mjs', './dist/index.esm.min.js')
}
},
],
},
// index.js
// usage
// <script src="index.js"
{
file: "dist/index.js",
format: "umd",
name: "MutablePromise",
exports: "default",
sourcemap: true,
},
// index.min.js
{
file: "dist/index.min.js",
format: "umd",
name: "MutablePromise",
exports: "default",
sourcemap: true,
plugins: [
plugin_terser_es6,
],
},
],
},
]
};