rollup.config.js raw
1 import { spawn } from "child_process";
2 import svelte from "rollup-plugin-svelte";
3 import commonjs from "@rollup/plugin-commonjs";
4 import terser from "@rollup/plugin-terser";
5 import resolve from "@rollup/plugin-node-resolve";
6 import livereload from "rollup-plugin-livereload";
7 import css from "rollup-plugin-css-only";
8 import copy from "rollup-plugin-copy";
9 import replace from "@rollup/plugin-replace";
10
11 const production = !process.env.ROLLUP_WATCH;
12
13 // Standalone mode configuration (for dashboard that connects to remote relay)
14 const standaloneMode = process.env.STANDALONE_MODE === 'true';
15 const defaultRelayUrl = process.env.DEFAULT_RELAY_URL || '';
16
17 // In dev mode, output to public/ so sirv can serve it
18 // In production, output to dist/ for embedding
19 const outputDir = production ? "dist" : "public";
20
21 function serve() {
22 let server;
23
24 function toExit() {
25 if (server) server.kill(0);
26 }
27
28 return {
29 writeBundle() {
30 if (server) return;
31 server = spawn("npm", ["run", "start", "--", "--dev"], {
32 stdio: ["ignore", "inherit", "inherit"],
33 shell: true,
34 });
35
36 process.on("SIGTERM", toExit);
37 process.on("exit", toExit);
38 },
39 };
40 }
41
42 export default {
43 input: "src/main.js",
44 output: {
45 sourcemap: true,
46 format: "iife",
47 name: "app",
48 file: `${outputDir}/bundle.js`,
49 },
50 plugins: [
51 // Replace environment variables at build time (for standalone mode)
52 replace({
53 preventAssignment: true,
54 'process.env.STANDALONE_MODE': JSON.stringify(standaloneMode ? 'true' : 'false'),
55 'process.env.DEFAULT_RELAY_URL': JSON.stringify(defaultRelayUrl),
56 }),
57
58 svelte({
59 compilerOptions: {
60 // enable run-time checks when not in production
61 dev: !production,
62 },
63 }),
64 // we'll extract any component CSS out into
65 // a separate file - better for performance
66 css({ output: "bundle.css" }),
67
68 // If you have external dependencies installed from
69 // npm, you'll most likely need these plugins. In
70 // some cases you'll need additional configuration -
71 // consult the documentation for details:
72 // https://github.com/rollup/plugins/tree/master/packages/commonjs
73 resolve({
74 browser: true,
75 dedupe: ["svelte"],
76 exportConditions: ["svelte"],
77 }),
78 commonjs(),
79
80 // In dev mode, call `npm run start` once
81 // the bundle has been generated
82 !production && serve(),
83
84 // Watch the `public` directory and refresh the
85 // browser on changes when not in production
86 !production && livereload("public"),
87
88 // If we're building for production (npm run build
89 // instead of npm run dev), minify
90 production && terser(),
91
92 // Copy static files from public to dist (only in production)
93 production && copy({
94 targets: [
95 { src: 'public/index.html', dest: 'dist' },
96 { src: 'public/global.css', dest: 'dist' },
97 { src: 'public/favicon.png', dest: 'dist' },
98 { src: 'public/orly.png', dest: 'dist' },
99 { src: 'public/manifest.json', dest: 'dist' },
100 { src: 'public/sw.js', dest: 'dist' },
101 { src: 'public/icon-192.png', dest: 'dist' },
102 { src: 'public/icon-512.png', dest: 'dist' }
103 ]
104 }),
105 ],
106 watch: {
107 clearScreen: false,
108 },
109 };
110