|
| 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 pkg from './package.json' |
| 7 | + |
| 8 | +const production = !process.env.ROLLUP_WATCH |
| 9 | + |
| 10 | +const name = pkg.name |
| 11 | + .replace(/^(@\S+\/)?(svelte-)?(\S+)/, '$3') |
| 12 | + .replace(/^\w/, m => m.toUpperCase()) |
| 13 | + .replace(/-\w/g, m => m[1].toUpperCase()) |
| 14 | + |
| 15 | +function serve () { |
| 16 | + let server |
| 17 | + function toExit () { |
| 18 | + if (server) server.kill(0) |
| 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 | + process.on('SIGTERM', toExit) |
| 28 | + process.on('exit', toExit) |
| 29 | + } |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +export default { |
| 34 | + input: 'docs/main.js', |
| 35 | + output: [ |
| 36 | + { sourcemap: true, format: 'iife', name: 'app', file: 'docs/build/bundle.js' }, |
| 37 | + production && { file: pkg.module, format: 'es' }, |
| 38 | + production && { file: pkg.main, format: 'umd', name } |
| 39 | + ], |
| 40 | + plugins: [ |
| 41 | + svelte({ |
| 42 | + compilerOptions: { |
| 43 | + dev: !production, |
| 44 | + css: true |
| 45 | + }, |
| 46 | + emitCss: false |
| 47 | + }), |
| 48 | + resolve({ |
| 49 | + browser: true, |
| 50 | + dedupe: ['svelte'] |
| 51 | + }), |
| 52 | + commonjs(), |
| 53 | + !production && serve(), |
| 54 | + !production && livereload('docs'), |
| 55 | + production && terser() |
| 56 | + ], |
| 57 | + watch: { |
| 58 | + clearScreen: false |
| 59 | + } |
| 60 | +} |
0 commit comments