forked from Festify/app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
101 lines (94 loc) · 3.28 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
101
import historyApi from 'connect-history-api-fallback';
import * as fs from 'fs';
import minify from 'rollup-plugin-babel-minify';
import cjs from 'rollup-plugin-commonjs';
import copy from 'rollup-plugin-copy';
import nodeGlobals from 'rollup-plugin-node-globals';
import nodeBuiltins from 'rollup-plugin-node-builtins';
import nodeResolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import minifyLit from '@mraerino/rollup-plugin-minifyliterals';
import browsersync from 'rollup-plugin-browsersync';
import replace from 'rollup-plugin-replace';
import visualizer from 'rollup-plugin-visualizer';
import path from 'path';
const distTarget = './build';
const dist = (dest = "") => path.join(distTarget, dest);
const srcTarget = './src';
const src = (dest = "") => path.join(srcTarget, dest);
const isProduction = process.env.NODE_ENV === 'production';
if (!fs.existsSync('build')) {
fs.mkdirSync('build');
}
export default {
input: src('index.ts'),
output: {
file: dist('index.js'),
format: 'iife',
sourcemap: true,
},
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
}),
nodeBuiltins(),
nodeResolve({
module: true,
jsnext: true,
browser: true,
customResolveOptions: {
packageFilter: pkg => {
if (pkg['module']) {
pkg['main'] = pkg['module'];
} else if (pkg['jsnext:main']) {
pkg['main'] = pkg['jsnext:main'];
}
const fixedPackages = [
'@firebase/app',
'@firebase/database',
'@firebase/functions',
'@firebase/util',
];
if (fixedPackages.indexOf(pkg.name) !== -1) {
pkg['browser'] = pkg.module;
}
return pkg;
},
},
}),
typescript(),
copy({
'node_modules/@webcomponents/webcomponentsjs': dist('node_modules/@webcomponents/webcomponentsjs'),
'assets': dist(''),
[src('index.html')]: dist('index.html'),
}),
cjs(),
nodeGlobals(),
isProduction ? minifyLit({
include: ['src/app.ts', 'src/{components,views}/**', 'node_modules/@polymer/{paper,iron}-*/**'],
includeExtension: ['.ts', '.js'],
literals: false,
htmlminifier: {
minifyCSS: true, // causes some kind of trouble currently
collapseWhitespace: true
}
}) : null,
isProduction ? minify({ comments: false }) : null,
!!process.env.ROLLUP_WATCH ? browsersync({
port: process.env.PORT || 3000,
server: {
baseDir: dist(),
middleware: [historyApi()]
},
open: false,
ui: false
}) : null,
visualizer({
filename: 'build/stats.html',
}),
].filter(plugin => plugin !== null),
onwarn: err => console.error(err.toString()),
watch: {
include: 'src/**/*'
}
};