]> git.openstreetmap.org Git - nominatim-ui.git/blob - rollup.config.js
Rebundle latest version
[nominatim-ui.git] / rollup.config.js
1 import svelte from 'rollup-plugin-svelte';
2 import commonjs from '@rollup/plugin-commonjs';
3 import resolve from '@rollup/plugin-node-resolve';
4 import livereload from 'rollup-plugin-livereload';
5 import { terser } from 'rollup-plugin-terser';
6 import { spawn } from 'child_process';
7 import css from 'rollup-plugin-css-only';
8 import { readFileSync, writeFileSync } from 'fs';
9
10 const production = !process.env.ROLLUP_WATCH;
11
12 function serve() {
13   let server;
14
15   function toExit() {
16     if (server) server.kill(0);
17   }
18
19   return {
20     writeBundle() {
21       if (server) return;
22       server = spawn('yarn', ['start', '-d'], {
23         stdio: ['ignore', 'inherit', 'inherit'],
24         shell: true
25       });
26
27       process.on('SIGTERM', toExit);
28       process.on('exit', toExit);
29     }
30   };
31 }
32
33 export default {
34   input: 'src/main.js',
35   output: {
36     sourcemap: true,
37     format: 'iife',
38     name: 'app',
39     file: 'dist/build/bundle.js'
40   },
41   plugins: [
42     svelte({
43       compilerOptions: {
44         // enable run-time checks when not in production
45         dev: !production
46       }
47     }),
48     css({
49       // output: function (styles, styleNodes) {
50       output: function (styles) {
51         // make sure global_styles.css gets appended to bundle.css,
52         // not prepended.
53         // The ':global()' rules (https://svelte.dev/docs#style) get
54         // prepended so we can't use them to overwrite bootstrap.css
55         // rules
56         let global_styles = readFileSync('src/global_style.css');
57         styles += global_styles;
58         writeFileSync('dist/build/bundle.css', styles);
59       }
60     }),
61
62     // If you have external dependencies installed from
63     // npm, you'll most likely need these plugins. In
64     // some cases you'll need additional configuration -
65     // consult the documentation for details:
66     // https://github.com/rollup/plugins/tree/master/packages/commonjs
67     resolve({
68       browser: true,
69       dedupe: ['svelte']
70     }),
71     commonjs(),
72
73     // In dev mode, call `npm run start` once
74     // the bundle has been generated
75     !production && serve(),
76
77     // Watch the `dist` directory and refresh the
78     // browser on changes when not in production
79     !production && livereload('dist'),
80
81     // If we're building for production (npm run build
82     // instead of npm run dev), minify
83     production && terser()
84   ],
85   watch: {
86     clearScreen: false
87   }
88 };