-
Notifications
You must be signed in to change notification settings - Fork 160
/
rollup.config.js
86 lines (81 loc) · 2 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
import { babel } from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
import nodent from 'rollup-plugin-nodent';
import license from 'rollup-plugin-license';
import copy from 'rollup-plugin-copy';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import path from 'path';
import { visualizer } from 'rollup-plugin-visualizer';
const pkg = require('./package.json');
const isProduction = process.env.BUILD === 'production';
const notExternal = ['uzip'];
const external = Object.keys(pkg.dependencies).filter(
(value) => !notExternal.includes(value),
);
const plugins = [
replace({
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify(process.env.BUILD),
'process.env.BUILD': JSON.stringify(process.env.BUILD),
__buildDate__: () => JSON.stringify(new Date()),
__buildVersion__: JSON.stringify(pkg.version),
},
}),
nodeResolve(),
nodent({ noRuntime: true, promises: true }),
commonjs(),
babel({
babelHelpers: 'bundled',
}),
isProduction
&& terser({
keep_fnames: true,
mangle: { reserved: ['CustomFile', 'CustomFileReader', 'UPNG', 'UZIP'] },
}),
license({
sourcemap: true,
banner:
'<%= _.startCase(pkg.name) %>\nv<%= pkg.version %>\nby <%= pkg.author %>\n<%= pkg.repository.url %>',
}),
copy({
targets: [
{
src: 'lib/index.d.ts',
dest: path.dirname(pkg.types),
rename: path.basename(pkg.types),
},
],
}),
visualizer({
open: false,
gzipSize: true,
brotliSize: true,
}),
];
export default {
input: 'lib/index.js',
plugins,
external,
output: [
{
file: pkg.main,
name: 'imageCompression',
format: 'umd',
sourcemap: true,
globals: {
uzip: 'UZIP',
},
},
{
file: pkg.module,
format: 'es',
sourcemap: true,
globals: {
uzip: 'UZIP',
},
},
],
};