rollup.config.js 2.3 KB

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