rollup.config.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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(
  56. "npm",
  57. ["run", "start", "--", "--dev"],
  58. {
  59. stdio: ["ignore", "inherit", "inherit"],
  60. shell: true,
  61. }
  62. );
  63. process.on("SIGTERM", toExit);
  64. process.on("exit", toExit);
  65. },
  66. };
  67. }