1
- import babel from 'rollup- plugin-babel' ;
1
+ import { babel } from '@ rollup/ plugin-babel' ;
2
2
import { terser } from 'rollup-plugin-terser' ;
3
3
import nodent from 'rollup-plugin-nodent' ;
4
4
import license from 'rollup-plugin-license' ;
5
5
import copy from 'rollup-plugin-copy' ;
6
6
import { nodeResolve } from '@rollup/plugin-node-resolve' ;
7
7
import commonjs from '@rollup/plugin-commonjs' ;
8
+ import replace from '@rollup/plugin-replace' ;
8
9
import path from 'path' ;
9
10
10
11
const pkg = require ( './package.json' ) ;
11
12
12
- const notExternal = [
13
- 'uzip' ,
14
- ] ;
15
- const external = Object . keys ( pkg . dependencies ) . filter ( ( value ) => ! notExternal . includes ( value ) ) ;
13
+ const isProduction = process . env . BUILD === 'production' ;
14
+
15
+ const notExternal = [ 'uzip' ] ;
16
+ const external = Object . keys ( pkg . dependencies ) . filter (
17
+ ( value ) => ! notExternal . includes ( value ) ,
18
+ ) ;
19
+ external . push ( / @ b a b e l \/ r u n t i m e / ) ;
16
20
17
21
const plugins = [
18
- nodent ( { noRuntime : true , promises : true } ) ,
19
- babel ( ) ,
20
- terser ( {
21
- keep_fnames : true ,
22
- mangle : { reserved : [ 'CustomFile' , 'CustomFileReader' , 'UPNG' , 'UZIP' ] } ,
22
+ replace ( {
23
+ preventAssignment : true ,
24
+ values : {
25
+ 'process.env.NODE_ENV' : JSON . stringify ( process . env . BUILD ) ,
26
+ 'process.env.BUILD' : JSON . stringify ( process . env . BUILD ) ,
27
+ __buildDate__ : ( ) => JSON . stringify ( new Date ( ) ) ,
28
+ __buildVersion__ : JSON . stringify ( pkg . version ) ,
29
+ } ,
30
+ } ) ,
31
+ isProduction && nodent ( { noRuntime : true , promises : true } ) ,
32
+ nodeResolve ( ) ,
33
+ commonjs ( ) ,
34
+ babel ( {
35
+ babelHelpers : 'bundled' ,
23
36
} ) ,
37
+ isProduction
38
+ && terser ( {
39
+ keep_fnames : true ,
40
+ mangle : { reserved : [ 'CustomFile' , 'CustomFileReader' , 'UPNG' , 'UZIP' ] } ,
41
+ } ) ,
24
42
license ( {
25
43
sourcemap : true ,
26
- banner : '<%= _.startCase(pkg.name) %>\nv<%= pkg.version %>\nby <%= pkg.author %>\n<%= pkg.repository.url %>' ,
44
+ banner :
45
+ '<%= _.startCase(pkg.name) %>\nv<%= pkg.version %>\nby <%= pkg.author %>\n<%= pkg.repository.url %>' ,
27
46
} ) ,
28
47
copy ( {
29
48
targets : [
30
- { src : 'lib/index.d.ts' , dest : path . dirname ( pkg . types ) , rename : path . basename ( pkg . types ) } ,
49
+ {
50
+ src : 'lib/index.d.ts' ,
51
+ dest : path . dirname ( pkg . types ) ,
52
+ rename : path . basename ( pkg . types ) ,
53
+ } ,
31
54
] ,
32
55
} ) ,
33
- nodeResolve ( ) ,
34
- commonjs ( ) ,
35
56
] ;
36
57
37
58
export default {
@@ -56,6 +77,5 @@ export default {
56
77
uzip : 'UZIP' ,
57
78
} ,
58
79
} ,
59
-
60
80
] ,
61
81
} ;
0 commit comments