rollup.config.js 1.7 KB

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