1- // Rollup plugins.
21import { babel } from '@rollup/plugin-babel' ;
32import commonjs from '@rollup/plugin-commonjs' ;
43import postcss from 'rollup-plugin-postcss' ;
54import replace from '@rollup/plugin-replace' ;
65import resolve from '@rollup/plugin-node-resolve' ;
76import url from '@rollup/plugin-url' ;
8-
97import cssnano from 'cssnano' ;
108import terser from '@rollup/plugin-terser' ;
119
10+ // Dev plugins
11+ import serve from 'rollup-plugin-serve' ;
12+ import livereload from 'rollup-plugin-livereload' ;
13+
14+ const isDev = process . env . ROLLUP_WATCH === 'true' ;
15+
1216export default {
1317 input : 'src/index-build.js' ,
1418 output : {
@@ -26,21 +30,28 @@ export default {
2630 exclude : 'node_modules/process-es6/**'
2731 } ) ,
2832 replace ( {
29- 'process.env.NODE_ENV' : JSON . stringify ( 'production' ) ,
30- ' preventAssignment' : true
33+ 'process.env.NODE_ENV' : JSON . stringify ( isDev ? 'development' : 'production' ) ,
34+ preventAssignment : true
3135 } ) ,
3236 url ( ) ,
3337 postcss ( {
34- extensions : [ '.css' ] ,
38+ extensions : [ '.css' ] ,
3539 plugins : [ cssnano ( ) ]
3640 } ) ,
3741 babel ( {
3842 babelrc : false ,
3943 exclude : 'node_modules/**' ,
4044 babelHelpers : 'bundled' ,
41- presets : [ '@babel/preset-env' , '@babel/preset-react' ] ,
42- plugins : [ '@babel/plugin-proposal-export-default-from' ]
45+ presets : [ '@babel/preset-env' , '@babel/preset-react' ] ,
46+ plugins : [ '@babel/plugin-proposal-export-default-from' ]
47+ } ) ,
48+ ! isDev && terser ( ) , // only minify in production
49+ isDev && serve ( {
50+ open : true ,
51+ contentBase : [ 'build' , 'public' ] ,
52+ host : '0.0.0.0' ,
53+ port : 5000
4354 } ) ,
44- terser ( )
45- ]
55+ isDev && livereload ( { watch : 'build' } )
56+ ] . filter ( Boolean )
4657} ;
0 commit comments