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