-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
executable file
·78 lines (76 loc) · 2.7 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
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import terser from "@rollup/plugin-terser";
import resolve from '@rollup/plugin-node-resolve';
import { readFileSync } from "fs";
const
pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")),
globals={ "jsonstat-toolkit": "JSONstat" },
external=["jsonstat-toolkit"],
preamble=`// ${pkg.name} v${pkg.version} Copyright ${(new Date).getFullYear()} ${pkg.author.name} ${pkg.homepage}`,
plugins=[
json(),
terser({
output: { preamble }
})
]
;
export default [
{
input: "./src/index.js",
external,
output: [
{
name: "JSONstatUtils",
file: pkg.unpkg,
format: "iife",
globals
}
],
plugins: [
replace({
preventAssignment: true,
__IE__: 'Array.prototype.reduce||Object.defineProperty(Array.prototype,"reduce",{value:function(r){if(null===this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof r)throw new TypeError(r+" is not a function");var e,t=Object(this),n=t.length>>>0,o=0;if(arguments.length>=2)e=arguments[1];else{for(;o<n&&!(o in t);)o++;if(o>=n)throw new TypeError("Reduce of empty array with no initial value");e=t[o++]}for(;o<n;)o in t&&(e=r(e,t[o],o,t)),o++;return e}}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(r){if(null==this)throw TypeError(\'"this" is null or not defined\');var e=Object(this),t=e.length>>>0;if("function"!=typeof r)throw TypeError("predicate must be a function");for(var n=arguments[1],o=0;o<t;){var i=e[o];if(r.call(n,i,o,e))return i;o++}},configurable:!0,writable:!0}),Array.prototype.findIndex||Object.defineProperty(Array.prototype,"findIndex",{value:function(r){if(null==this)throw new TypeError(\'"this" is null or not defined\');var e=Object(this),t=e.length>>>0;if("function"!=typeof r)throw new TypeError("predicate must be a function");for(var n=arguments[1],o=0;o<t;){var i=e[o];if(r.call(n,i,o,e))return o;o++}return-1},configurable:!0,writable:!0});'
}),
...plugins
]
},
{
input: "./src/index.js",
external,
output: [
{
file: pkg.module,
format: "esm",
globals
},
{
file: pkg.main,
format: "cjs",
globals
},
],
plugins: [
replace({
preventAssignment: true,
__IE__: ''
}),
...plugins
]
},
{
input: "./src/index.js",
output: {
file: "import.mjs",
format: "esm",
},
plugins: [
replace({
preventAssignment: true,
__IE__: ''
}),
resolve({mainFields: ["browser"]}),
...plugins
]
}
]