-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrollup.config.build.js
97 lines (87 loc) · 3.09 KB
/
rollup.config.build.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
95
96
97
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import ts from '@wessberg/rollup-plugin-ts';
import sourceMaps from 'rollup-plugin-sourcemaps';
import polyfill from 'rollup-plugin-polyfill';
import {terser} from 'rollup-plugin-terser';
const legacyDecode = {outputDir: 'lib/asm/decompress/', inputDir: 'src/components/asm/decompress/'};
const legacyFull = {outputDir: 'lib/asm/', inputDir: 'src/components/asm/'};
const modernDecode = {outputDir: 'lib/wasm/decompress/', inputDir: 'src/components/wasm/decompress/'};
const modernFull = {outputDir: 'lib/wasm/', inputDir: 'src/components/wasm/'};
const defaultCodec = {outputDir: 'lib/', inputDir: 'src/components/default/'};
const defaultDec = {outputDir: 'lib/decompress/', inputDir: 'src/components/default/decompress/'};
const packageName = 'zstdCodec';
const legacyPolyfill = polyfill([
'core-js/features/object/assign',
'core-js/features/typed-array/copy-within',
'core-js/features/promise/any',
'core-js/features/promise/finally',
'core-js/features/promise/try',
'core-js/features/promise/all-settled',
'core-js/features/promise/index',
]);
const umdFactory = (inputDir, outputDir, isLegacy) => {
const plugins = [
resolve(),
commonjs({
requireReturnsDefault: false,
ignore: id => {
return ['path', 'fs'].includes(id);
},
}),
ts(),
sourceMaps(),
terser({ecma: 5}),
];
if (isLegacy) plugins.push(legacyPolyfill);
return {
input: inputDir + 'index.ts',
output: {
name: packageName,
file: outputDir + 'index.umd.js',
format: 'umd',
sourcemap: true,
},
plugins,
};
};
const msFactory = (inputDir, outputDir, isLegacy) => {
const plugins = [
commonjs({
ignore: id => ['path', 'fs'].includes(id),
}),
ts(),
sourceMaps(),
terser({ecma: 5}),
];
if (isLegacy) plugins.push(legacyPolyfill);
return {
input: inputDir + 'index.ts',
external: ['ms'],
plugins,
output: [
{file: outputDir + 'index.cjs.js', format: 'cjs', sourcemap: true, exports: 'named'},
{file: outputDir + 'index.js', format: 'es', sourcemap: true, exports: 'named'},
],
};
};
export default [
// DECOMPRESS - WASM
umdFactory(modernDecode.inputDir, modernDecode.outputDir, false),
msFactory(modernDecode.inputDir, modernDecode.outputDir, false),
// FULL - WASM
umdFactory(modernFull.inputDir, modernFull.outputDir, false),
msFactory(modernFull.inputDir, modernFull.outputDir, false),
// DECOMPRESS - ASM
umdFactory(legacyDecode.inputDir, legacyDecode.outputDir, true),
msFactory(legacyDecode.inputDir, legacyDecode.outputDir, true),
// FULL - ASM
umdFactory(legacyFull.inputDir, legacyFull.outputDir, true),
msFactory(legacyFull.inputDir, legacyFull.outputDir, true),
// DECOMPRESS - ASM - WASM
umdFactory(defaultDec.inputDir, defaultDec.outputDir, true),
msFactory(defaultDec.inputDir, defaultDec.outputDir, true),
// FULL - ASM - WASM
umdFactory(defaultCodec.inputDir, defaultCodec.outputDir, true),
msFactory(defaultCodec.inputDir, defaultCodec.outputDir, true),
];