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