-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathrollup.config.renderer.mjs
More file actions
109 lines (101 loc) · 3.19 KB
/
rollup.config.renderer.mjs
File metadata and controls
109 lines (101 loc) · 3.19 KB
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
105
106
107
108
109
import fs from 'fs';
import path from 'path';
import terser from '@rollup/plugin-terser';
import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import polyfills from 'rollup-plugin-polyfill-node';
import json from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import copy from 'rollup-plugin-copy';
import { sveltePreprocess } from 'svelte-preprocess';
import { babel, getBabelOutputPlugin } from '@rollup/plugin-babel';
// import config Babel via import ESM
import babelConfig from './babel.config.json' with { type: 'json' };
import babelNodeOutput from './babel.node-output.json' with { type: 'json' };
import babelRendererOutput from './babel.renderer-output.json' with { type: 'json' };
import babelRendererPolyfills from './babel.renderer-polyfills.json' with { type: 'json' };
// determines environment
const baseResolveOpts = { browser: false, exportConditions: ['node', 'svelte'], preferBuiltins: true };
// common plugins
const replaceOpts = {
preventAssignment: false,
delimiters: ['', ''],
values: {
'fs/promises")': 'fs").promises',
"fs/promises')": "fs').promises",
'getFilename()': '__filename',
'getDirname()': '__dirname'
}
}
// Check if this is a production build
const isProduction = process.env.NODE_ENV === 'production' || process.argv.includes('--production')
// Svelte renderer plugins
const rendererPlugins = [
svelte({
emitCss: false,
preprocess: sveltePreprocess(),
compilerOptions: { css: 'injected', compatibility: { componentApi: 4 } }
}),
babel({ ...babelRendererPolyfills, babelHelpers: 'bundled', extensions: ['.js', '.svelte'], skipPreflightCheck: true }),
resolve({
browser: true,
exportConditions: ['svelte', 'node', 'import', 'default'],
extensions: ['.js', '.mjs', '.json', '.svelte'],
preferBuiltins: false,
}),
commonjs({
include: [
'node_modules/**',
'www/nodejs/modules/**'
],
extensions: ['.js', '.cjs']
}),
json(),
polyfills(),
replace(replaceOpts),
isProduction && terser({
compress: {
drop_console: false,
drop_debugger: true,
pure_funcs: ['console.debug']
}
})
].filter(Boolean);
// Watch options
const watchOpts = {
include: ['www/nodejs/renderer/src/**', 'www/nodejs/modules/**'],
exclude: ['node_modules/**']
};
// Main Svelte app and Capacitor bridge bundle
export default [
{
input: 'www/nodejs/renderer/src/App.svelte',
output: {
file: 'www/nodejs/renderer/dist/App.js',
format: 'iife',
name: 'App',
sourcemap: !isProduction
},
plugins: rendererPlugins,
watch: watchOpts,
external: ['electron', /.+\.(node|native)$/]
},
{
input: 'capacitor.mjs',
output: {
file: 'www/nodejs/renderer/dist/capacitor.js',
format: 'iife',
name: 'capacitor',
inlineDynamicImports: true,
sourcemap: !isProduction
},
plugins: rendererPlugins,
watch: watchOpts,
external: ['electron', /.+\.(node|native)$/]
}
];
// Copy static assets (executed separately)
if (isProduction || process.argv.includes('--copy-assets')) {
// This will be handled by a separate script or manual copy
}