rollup.config.js (1735B)
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 8 const production = !process.env.ROLLUP_WATCH; 9 10 function serve() { 11 let server; 12 13 function toExit() { 14 if (server) server.kill(0); 15 } 16 17 return { 18 writeBundle() { 19 if (server) return; 20 server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], { 21 stdio: ['ignore', 'inherit', 'inherit'], 22 shell: true 23 }); 24 25 process.on('SIGTERM', toExit); 26 process.on('exit', toExit); 27 } 28 }; 29 } 30 31 export default { 32 input: 'src/main.js', 33 output: { 34 sourcemap: true, 35 format: 'iife', 36 name: 'app', 37 file: 'public/build/bundle.js' 38 }, 39 plugins: [ 40 svelte({ 41 compilerOptions: { 42 // enable run-time checks when not in production 43 dev: !production 44 } 45 }), 46 // we'll extract any component CSS out into 47 // a separate file - better for performance 48 css({ output: 'bundle.css' }), 49 50 // If you have external dependencies installed from 51 // npm, you'll most likely need these plugins. In 52 // some cases you'll need additional configuration - 53 // consult the documentation for details: 54 // https://github.com/rollup/plugins/tree/master/packages/commonjs 55 resolve({ 56 browser: true, 57 dedupe: ['svelte'] 58 }), 59 commonjs(), 60 61 // Watch the `public` directory and refresh the 62 // browser on changes when not in production 63 !production && livereload('public'), 64 65 // If we're building for production (npm run build 66 // instead of npm run dev), minify 67 production && terser() 68 ], 69 watch: { 70 clearScreen: false 71 } 72 };