forked from getsentry/sentry-electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
78 lines (70 loc) · 1.83 KB
/
rollup.config.mjs
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
import { builtinModules } from 'node:module';
import { resolve } from 'node:path';
import { readFileSync } from 'node:fs';
import typescript from '@rollup/plugin-typescript';
const pkgJson = JSON.parse(readFileSync(resolve(process.cwd(), 'package.json')));
const dependencies = Object.keys(pkgJson.dependencies || {});
const external = [...builtinModules, 'electron', ...dependencies];
const outputOptions = {
sourcemap: true,
strict: false,
freeze: false,
externalLiveBindings: false,
generatedCode: {
preset: 'es2015',
symbols: false,
},
};
// a simple plugin that adds a package.json file with type: module
const modulePackageJson = {
name: 'package-json-module-type',
generateBundle() {
this.emitFile({
type: 'asset',
fileName: 'package.json',
source: '{"type": "module"}',
});
},
};
function transpileFiles(format, input, outDir) {
return {
input,
output: {
...outputOptions,
format,
dir: outDir,
preserveModules: true,
},
treeshake: { moduleSideEffects: false },
plugins: [
typescript({
outDir,
tsconfig: './tsconfig.build.json',
}),
format === 'esm' ? modulePackageJson : {},
],
external,
};
}
function bundlePreload(format, input, output) {
return {
input,
output: {
...outputOptions,
format,
file: output,
},
plugins: [
typescript({
tsconfig: './tsconfig.preload.json',
}),
],
external,
};
}
export default [
transpileFiles('cjs', ['src/index.ts', 'src/main/index.ts', 'src/renderer/index.ts'], '.'),
transpileFiles('esm', ['src/index.ts', 'src/main/index.ts', 'src/renderer/index.ts'], './esm'),
bundlePreload('cjs', 'src/preload/index.ts', './preload/index.js'),
bundlePreload('esm', 'src/preload/index.ts', './esm/preload/index.js'),
];