rollup.config.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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('node: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. postcss: true,
  39. }),
  40. compilerOptions: {
  41. // enable run-time checks when not in production
  42. dev: !production,
  43. },
  44. }),
  45. // we'll extract any component CSS out into
  46. // a separate file - better for performance
  47. css({ output: 'bundle.css' }),
  48. // If you have external dependencies installed from
  49. // npm, you'll most likely need these plugins. In
  50. // some cases you'll need additional configuration -
  51. // consult the documentation for details:
  52. // https://github.com/rollup/plugins/tree/master/packages/commonjs
  53. resolve({
  54. browser: true,
  55. dedupe: ['svelte', '@uppy/core'],
  56. }),
  57. commonjs(),
  58. typescript({
  59. sourceMap: !production,
  60. inlineSources: !production,
  61. }),
  62. // In dev mode, call `npm run start` once
  63. // the bundle has been generated
  64. !production && serve(),
  65. // Watch the `public` directory and refresh the
  66. // browser on changes when not in production
  67. !production && livereload('public'),
  68. // If we're building for production (npm run build
  69. // instead of npm run dev), minify
  70. production && terser(),
  71. ],
  72. watch: {
  73. clearScreen: false,
  74. },
  75. }