1- import babel from 'rollup- plugin-babel' ;
1+ import { babel } from '@ rollup/ plugin-babel' ;
22import { terser } from 'rollup-plugin-terser' ;
33import nodent from 'rollup-plugin-nodent' ;
44import license from 'rollup-plugin-license' ;
55import copy from 'rollup-plugin-copy' ;
66import { nodeResolve } from '@rollup/plugin-node-resolve' ;
77import commonjs from '@rollup/plugin-commonjs' ;
8+ import replace from '@rollup/plugin-replace' ;
89import path from 'path' ;
910
1011const pkg = require ( './package.json' ) ;
1112
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 / ) ;
1620
1721const 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' ,
2336 } ) ,
37+ isProduction
38+ && terser ( {
39+ keep_fnames : true ,
40+ mangle : { reserved : [ 'CustomFile' , 'CustomFileReader' , 'UPNG' , 'UZIP' ] } ,
41+ } ) ,
2442 license ( {
2543 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 %>' ,
2746 } ) ,
2847 copy ( {
2948 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+ } ,
3154 ] ,
3255 } ) ,
33- nodeResolve ( ) ,
34- commonjs ( ) ,
3556] ;
3657
3758export default {
@@ -56,6 +77,5 @@ export default {
5677 uzip : 'UZIP' ,
5778 } ,
5879 } ,
59-
6080 ] ,
6181} ;
0 commit comments