Advertisement
Guest User

svelte-cust-el-rollup

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