forked from zotero/zoterobib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
76 lines (71 loc) · 2.04 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
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import filesize from 'rollup-plugin-filesize';
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import sizes from 'rollup-plugin-sizes';
import wasm from '@rollup/plugin-wasm';
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
import terser from '@rollup/plugin-terser';
import alias from '@rollup/plugin-alias';
import virtual from '@rollup/plugin-virtual';
const isProduction = process.env.NODE_ENV?.startsWith('prod');
const config = {
input: './src/js/main.js',
external: [
'/static/js/citeproc-rs/citeproc_rs_wasm.js',
'cross-fetch/polyfill'
],
output: {
dir: './build/static',
format: 'iife',
sourcemap: !isProduction,
compact: isProduction
},
treeshake: {
moduleSideEffects: 'no-external',
},
plugins: [
resolve({
preferBuiltins: false,
mainFields: ['browser', 'module', 'main'],
extensions: ['.js', '.jsx', '.wasm'],
}),
json(),
wasm(),
webWorkerLoader({
targetPlatform: 'browser',
skipPlugins: ['resolve', 'json', 'wasm', 'commonjs', 'replace', 'babel', 'sizes', 'filesize']
}),
commonjs(),
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? 'development'),
}),
babel({
exclude: "node_modules/**",
extensions: ['.js', '.jsx'],
babelHelpers: 'runtime'
}),
filesize({ showMinifiedSize: false, showGzippedSize: !!process.env.DEBUG }),
]
};
if(process.env.DEBUG) {
config.plugins.splice(-1, 0, sizes());
}
if(isProduction) {
config.plugins.splice(0, 0, alias({
entries: [{
find: '@formatjs/icu-messageformat-parser',
replacement: '@formatjs/icu-messageformat-parser/no-parser'
}]
}));
config.plugins.push(terser({ safari10: true }));
config.external.push('./wdyr'); //exclude why-did-you-render from production
} else {
config.plugins.splice(0, 0, virtual({
'../../lang/compiled/en-US.json': 'export default {}',
}),)
}
export default config;