rollup.config.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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(
  19. 'npm',
  20. ['run', 'start', '--', '--dev'],
  21. {
  22. stdio: ['ignore', 'inherit', 'inherit'],
  23. shell: true
  24. }
  25. )
  26. process.on('SIGTERM', toExit)
  27. process.on('exit', toExit)
  28. }
  29. }
  30. }
  31. export default {
  32. input: 'src/main.ts',
  33. output: {
  34. sourcemap: true,
  35. format: 'iife',
  36. name: 'app',
  37. file: 'public/build/bundle.js'
  38. },
  39. plugins: [
  40. svelte({
  41. preprocess: sveltePreprocess(),
  42. compilerOptions: {
  43. // enable run-time checks when not in production
  44. dev: !production
  45. }
  46. }),
  47. // we'll extract any component CSS out into
  48. // a separate file - better for performance
  49. css({ output: 'bundle.css' }),
  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. typescript({
  61. sourceMap: !production,
  62. inlineSources: !production
  63. }),
  64. // In dev mode, call `npm run start` once
  65. // the bundle has been generated
  66. !production && serve(),
  67. // Watch the `public` directory and refresh the
  68. // browser on changes when not in production
  69. !production && livereload('public'),
  70. // If we're building for production (npm run build
  71. // instead of npm run dev), minify
  72. production && terser()
  73. ],
  74. watch: {
  75. clearScreen: false
  76. }
  77. }