Advertisement
Guest User

Untitled

a guest
Feb 18th, 2021
332
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 replace from '@rollup/plugin-replace';
  7.  
  8. const production = !process.env.ROLLUP_WATCH;
  9.  
  10. function serve() {
  11.     let server;
  12.  
  13.     function toExit() {
  14.         if (server) server.kill(0);
  15.     }
  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.  
  25.             process.on('SIGTERM', toExit);
  26.             process.on('exit', toExit);
  27.         }
  28.     };
  29. }
  30.  
  31. export default {
  32.     input: 'src/main.js',
  33.     output: {
  34.         sourcemap: true,
  35.         format: 'iife',
  36.         name: 'app',
  37.         file: 'public/build/bundle.js'
  38.     },
  39.     plugins: [
  40.         svelte({
  41.             // enable run-time checks when not in production
  42.             dev: !production,
  43.             // we'll extract any component CSS out into
  44.             // a separate file - better for performance
  45.             css: css => {
  46.                 css.write('bundle.css');
  47.             }
  48.         }),
  49.  
  50.         replace({
  51.             'process.env.NODE_ENV': JSON.stringify(process.env.NODE)
  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.  
  65.         // In dev mode, call `npm run start` once
  66.         // the bundle has been generated
  67.         !production && serve(),
  68.  
  69.         // Watch the `public` directory and refresh the
  70.         // browser on changes when not in production
  71.         !production && livereload('public'),
  72.  
  73.         // If we're building for production (npm run build
  74.         // instead of npm run dev), minify
  75.         production && terser(),
  76.  
  77.     ],
  78.     watch: {
  79.         clearScreen: false
  80.     }
  81. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement