rollup.config.js 1.9 KB

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