rollup.config.js 2.2 KB

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