This repository has been archived by the owner on Apr 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
100 lines (89 loc) · 2.33 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* eslint-disable max-len */// tslint:disable:max-line-length
import browserSync from 'browser-sync';
import buble from 'rollup-plugin-buble';
import commonjs from 'rollup-plugin-commonjs';
import historyApiFallback from 'connect-history-api-fallback';
import postcss from 'rollup-plugin-postcss';
import resolve from 'rollup-plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
const bs = browserSync.create();
const isProd = process.env.NODE_ENV === 'production' || !process.env.ROLLUP_WATCH;
const terserOpts = {
compress: {
drop_console: isProd,
drop_debugger: isProd,
negate_iife: false, // better performance when false
passes: 2,
pure_getters: true,
unsafe: true,
unsafe_proto: true,
},
mangle: {
properties: {
// Bad patterns: children, nodeName, pathname, previous
regex: /^(__.*|state|actions|attributes|isExact|exact|subscribe|detail|params|render|oncreate|onupdate|onremove|ondestroy)$/,
// debug: 'XX',
},
},
output: {
comments: !!process.env.DEBUG,
wrap_iife: true,
},
ecma: 8,
toplevel: true,
warnings: !!process.env.DEBUG,
};
// custom browser sync plugin
function browsersync() {
if (!bs.active) {
bs.init({
server: {
baseDir: 'dist',
directory: true,
middleware: [historyApiFallback()],
},
port: process.env.PORT || 1234,
open: false,
ghostMode: false,
logConnections: true,
});
}
return {
name: 'browsersync',
onwrite(bundle) {
bs.reload(bundle.dest);
},
};
}
export default {
input: 'src/index.js',
experimentalCodeSplitting: true,
experimentalDynamicImport: true,
output: {
file: 'dist/mc.js',
name: 'mc',
format: 'iife',
sourcemap: isProd,
interop: false, // saves bytes with externs
},
plugins: [
postcss({
extract: true,
sourceMap: true,
}),
commonjs(),
resolve({
jsnext: true,
extensions: ['.js', '.jsx', '.json', '.css'],
}),
buble({ jsx: 'h' }),
// PRODUCTION
isProd && terser(terserOpts),
// TODO: Asset cache invalidation
// TODO: Service worker & other nice PWA features (necessary?)
// ↳ https://github.com/GoogleChrome/workbox
// ↳ https://developers.google.com/web/tools/workbox/
// DEVELOPMENT
!isProd && browsersync(),
],
};