-
Notifications
You must be signed in to change notification settings - Fork 19
/
rollup.config.mjs
159 lines (143 loc) · 3.72 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
// Import assertion is still in experimental, and it fails in ESLint.
// import packageJson from './package.json' assert { type: 'json' };
import { readFileSync } from 'node:fs';
import buble from '@rollup/plugin-buble';
import terser from '@rollup/plugin-terser';
// MARK: - Setup variables
/**
* @typedef {Object} PackageJson
* @property {string} name
* @property {string} license
* @property {string} author
*/
/**
* Ref: https://github.com/eslint/eslint/discussions/15305
* @returns {PackageJson} The JSON object.
* @throws Error for missing properties.
*/
function importPackageJson() {
// @ts-ignore
const fileURL = new URL('./package.json', import.meta.url);
const { name, license, author } = JSON.parse(readFileSync(fileURL, 'utf8'));
if (!name && !license && !author) {
throw new Error();
}
return { name, license, author };
}
/** @type {PackageJson} */
const pkg = importPackageJson();
/** @type {import('rollup').OutputOptions} */
const outputCommons = {
indent: true, // as default.
banner: `\
/**
* Validid is a Javascript library to validate ID card number of Hong Kong, Taiwan, South Korea and China.
*
* Validid is open source in:
* https://github.com/Edditoria/validid
*
* Code released under the ${pkg.license} license:
* https://github.com/Edditoria/validid/blob/main/LICENSE.txt
*
* @author ${pkg.author}
* @license ${pkg.license}
*/
`,
};
// MARK: - Plugin options
/** @type {import('@rollup/plugin-buble').RollupBubleOptions} */
const bubleEsmOptions = {
target: { node: 8, safari: 11, chrome: 71 },
// transforms: { dangerousForOf: true },
};
/** @type {import('@rollup/plugin-buble').RollupBubleOptions} */
const bubleUmdOptions = {
target: { ie: 8 },
transforms: { dangerousForOf: true },
};
/** @type {import('@rollup/plugin-terser').Options} */
const terserEsmOptions = {
ecma: 2015,
keep_classnames: true,
compress: { arrows: false, typeofs: false },
// mangle: false,
format: {
comments: 'some', // as default.
},
};
/** @type {import('@rollup/plugin-terser').Options} */
const terserUmdOptions = {
ecma: 5,
ie8: true,
safari10: true,
keep_classnames: true,
compress: { arrows: false, typeofs: false },
// mangle: false,
format: {
comments: 'some', // as default.
},
};
// MARK: - Export objects
/**
* Rollup options:
* - Target ES6 aka ECMAScript 2015.
* - ESM; Not minified; In one file.
* @type {import('rollup').RollupOptions}
*/
const rollupEsm = {
input: 'tasks/resources/rollup-input/module.mjs',
output: {
...outputCommons,
file: `bundles/${pkg.name}.esm.mjs`,
format: 'esm',
},
plugins: [buble(bubleEsmOptions)],
};
/**
* Rollup options:
* - Target ES6 aka ECMAScript 2015.
* - ESM; Minified; In one file.
* @type {import('rollup').RollupOptions}
*/
const rollupEsmMin = {
input: 'tasks/resources/rollup-input/module.mjs',
output: {
...outputCommons,
file: `bundles/${pkg.name}.esm.min.mjs`,
format: 'esm',
},
plugins: [buble(bubleEsmOptions), terser(terserEsmOptions)],
};
/**
* Rollup options:
* - Target legacy browsers.
* - UMD; Not minified; In one file.
* @type {import('rollup').RollupOptions}
*/
const rollupUmd = {
input: 'tasks/resources/rollup-input/umd.mjs',
output: {
...outputCommons,
file: `bundles/${pkg.name}.umd.js`,
format: 'umd',
name: pkg.name,
},
plugins: [buble(bubleUmdOptions)],
};
/**
* Rollup options:
* - Target legacy browsers.
* - UMD; Minified; In one file.
* @type {import('rollup').RollupOptions}
*/
const rollupUmdMin = {
input: 'tasks/resources/rollup-input/umd.mjs',
output: {
...outputCommons,
file: `bundles/${pkg.name}.umd.min.js`,
format: 'umd',
name: pkg.name,
},
plugins: [buble(bubleUmdOptions), terser(terserUmdOptions)],
};
export default [rollupEsm, rollupEsmMin, rollupUmd, rollupUmdMin];