Advertisement
Guest User

Untitled

a guest
Nov 28th, 2020
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  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. import sveltePreprocess from 'svelte-preprocess';
  7. import typescript from '@rollup/plugin-typescript';
  8. import alias from "@rollup/plugin-alias";
  9. import path from "path";
  10.  
  11. const production = !process.env.ROLLUP_WATCH;
  12.  
  13. export default {
  14. input: 'src/main.ts',
  15. output: {
  16. sourcemap: true,
  17. format: 'iife',
  18. name: 'app',
  19. file: 'public/build/bundle.js'
  20. },
  21. onwarn: (message, warn) => {
  22. if (message.code === "CIRCULAR_DEPENDENCY") {
  23. return;
  24. }
  25. warn(message);
  26. },
  27. plugins: [
  28. alias({
  29. resolve: [".ts", ".svelte"],
  30. entries: [
  31. { find: "@src", replacement: path.resolve(__dirname, "src") },
  32. ]
  33. }),
  34. svelte({
  35. // enable run-time checks when not in production
  36. dev: !production,
  37. // we'll extract any component CSS out into
  38. // a separate file - better for performance
  39. css: css => {
  40. css.write('public/build/bundle.css');
  41. },
  42. preprocess: sveltePreprocess({
  43. aliases: ['ts', 'typescript']
  44. }),
  45. }),
  46.  
  47. // If you have external dependencies installed from
  48. // npm, you'll most likely need these plugins. In
  49. // some cases you'll need additional configuration -
  50. // consult the documentation for details:
  51. // https://github.com/rollup/plugins/tree/master/packages/commonjs
  52. resolve({
  53. browser: true,
  54. dedupe: ['svelte']
  55. }),
  56. commonjs(),
  57. typescript({
  58. sourceMap: !production,
  59. }),
  60.  
  61. // In dev mode, call `npm run start` once
  62. // the bundle has been generated
  63. !production && serve(),
  64.  
  65. // Watch the `public` directory and refresh the
  66. // browser on changes when not in production
  67. !production && livereload('public'),
  68.  
  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. };
  77.  
  78. function serve() {
  79. let started = false;
  80.  
  81. return {
  82. writeBundle() {
  83. if (!started) {
  84. started = true;
  85.  
  86. require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
  87. stdio: ['ignore', 'inherit', 'inherit'],
  88. shell: true
  89. });
  90. }
  91. }
  92. };
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement