rollup.config.js 2.0 KB

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