-
Notifications
You must be signed in to change notification settings - Fork 19
/
rollup.config.js
104 lines (97 loc) · 3.11 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
102
103
104
import * as path from 'path';
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';
import { visualizer } from "rollup-plugin-visualizer";
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',
'jsdom', // zotero-utilities/utilities.js:619 includes jsdom which is then
// treeshaken because we replace Zotero.isNode to false. To avoid
// bogus imports/warnings it also needs to be marked as external.
],
output: {
dir: './build/static',
format: 'iife',
sourcemap: !isProduction,
compact: isProduction
},
treeshake: {
preset: 'smallest',
moduleSideEffects: (id) => {
if (id.includes('core-js/')) {
return true;
}
if (id.includes('@formatjs/intl-')) {
return true;
}
if (!isProduction && id.includes('wdyr')) {
return true;
}
return false;
}
},
plugins: [
webWorkerLoader({
targetPlatform: 'browser',
skipPlugins: ['resolve', 'json', 'wasm', 'commonjs', 'replace', 'babel', 'sizes', 'visualizer', 'filesize']
}),
resolve({
modulePaths: [path.join(process.cwd(), 'modules')],
preferBuiltins: false,
mainFields: ['browser', 'main'],
extensions: ['.js', '.jsx', '.wasm'],
}),
json(),
wasm(),
commonjs(),
replace({
preventAssignment: true,
'Zotero.isNode': false,
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV ?? 'development'),
}),
babel({
// @floating-ui targets Safari >= 12, we target Safari >= 10, so we need to
// include @floating-ui in babel transpilation
babelrc: false,
include: ['src/js/**', 'modules/zotero-utilities/**', 'modules/web-common/**', 'node_modules/@floating-ui/**'],
babelHelpers: 'bundled'
}),
filesize({ showMinifiedSize: false, showGzippedSize: !!process.env.DEBUG }),
]
};
const commonAliases = [
{ find: /^core-js-pure\/(.*)/, replacement: 'core-js/$1' },
];
if(process.env.DEBUG) {
config.plugins.splice(0, 0, alias({ entries: commonAliases }));
config.plugins.splice(-1, 0, sizes());
config.plugins.splice(-1, 0, visualizer({ filename: `visualizer/${new Date().toJSON().slice(0, 10)}.html` }));
}
if(isProduction) {
config.plugins.splice(0, 0, alias({
entries: [...commonAliases, {
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;