-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
99 lines (95 loc) · 2.93 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
import path from 'path';
import fs from 'fs';
import { defineConfig } from 'rollup';
import json from '@rollup/plugin-json';
import alias from '@rollup/plugin-alias';
import ts from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import virtual from '@rollup/plugin-virtual';
import image from '@rollup/plugin-image';
import replace from '@rollup/plugin-replace';
const IN_PRODUCTION = process.env.NODE_ENV === 'production';
const DIR_OUTPUT = path.join(__dirname, 'dist');
const rollupDefine = {
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
__DEV__: String(!IN_PRODUCTION),
},
};
const ELECTRON = defineConfig({
external: [
'fs/promises',
'electron', // DO NOT USE REGEXP, WILL BREAK DYNAMIC IMPORT
],
input: {
bootstrap: 'electron/bootstrap.js',
renderer: 'electron/renderer.js',
},
output: {
dir: DIR_OUTPUT,
entryFileNames: '[name].js',
chunkFileNames: '[name]-[hash].js',
format: 'cjs',
interop: 'auto',
sourcemap: IN_PRODUCTION ? undefined : true,
},
plugins: [
replace(rollupDefine),
alias({
entries: [
{ find: 'e', replacement: path.resolve(__dirname, 'electron') },
],
}),
nodeResolve(),
json(),
image(),
IN_PRODUCTION && terser(),
],
});
// MUST use output.manualChunks, otherwise the bundles are shits.
const JS = defineConfig({
input: {
index: 'src/index.ts',
setting: 'src/setting/index.ts',
'web-worker': 'src/web-worker.ts',
'find-widget': 'src/find-widget/index.ts',
'nodejs-api': 'src/nodejs-api/index.ts',
},
output: {
dir: DIR_OUTPUT,
entryFileNames: 'js/[name].js',
chunkFileNames: 'js/[name]-[hash].js',
format: 'es',
sourcemap: IN_PRODUCTION ? undefined : 'inline',
manualChunks: undefined,
},
plugins: [
replace(rollupDefine),
virtual({
'in-plugin/sse': IN_PRODUCTION ? '' : fs.readFileSync('src/sse.js', 'utf-8'),
}),
// IMPORTANT: this typescript plugin must place before '@rollup/plugin-node-resolve'
// otherwise will occur some errors of "Circular dependencies"
ts({ tsconfig: 'src/tsconfig.json' }),
commonjs(),
nodeResolve(),
json(),
IN_PRODUCTION && terser(),
],
// perf: true,
onwarn(warnings, warn) {
if (warnings.code === 'UNRESOLVED_IMPORT') {
// Modules are resolved by typescript
return;
}
if (warnings.code === 'EVAL') {
// eval() is currently necessary for Macros
return;
}
warn(warnings);
},
});
export default [ELECTRON, JS];