|
| 1 | +import resolve from 'rollup-plugin-node-resolve'; |
| 2 | +import replace from 'rollup-plugin-replace'; |
| 3 | +import commonjs from 'rollup-plugin-commonjs'; |
| 4 | +import svelte from 'rollup-plugin-svelte'; |
| 5 | +import babel from 'rollup-plugin-babel'; |
| 6 | +import { terser } from 'rollup-plugin-terser'; |
| 7 | +import config from 'sapper/config/rollup.js'; |
| 8 | +import pkg from './package.json'; |
| 9 | + |
| 10 | +const mode = process.env.NODE_ENV; |
| 11 | +const dev = mode === 'development'; |
| 12 | +const legacy = !!process.env.SAPPER_LEGACY_BUILD; |
| 13 | + |
| 14 | +const onwarn = (warning, onwarn) => (warning.code === 'CIRCULAR_DEPENDENCY' && warning.message.includes('/@sapper/')) || onwarn(warning); |
| 15 | + |
| 16 | +export default { |
| 17 | + client: { |
| 18 | + input: config.client.input(), |
| 19 | + output: config.client.output(), |
| 20 | + plugins: [ |
| 21 | + replace({ |
| 22 | + 'process.browser': true, |
| 23 | + 'process.env.NODE_ENV': JSON.stringify(mode) |
| 24 | + }), |
| 25 | + svelte({ |
| 26 | + dev, |
| 27 | + hydratable: true, |
| 28 | + emitCss: true |
| 29 | + }), |
| 30 | + resolve(), |
| 31 | + commonjs(), |
| 32 | + |
| 33 | + legacy && babel({ |
| 34 | + extensions: ['.js', '.mjs', '.html', '.svelte'], |
| 35 | + runtimeHelpers: true, |
| 36 | + exclude: ['node_modules/@babel/**'], |
| 37 | + presets: [ |
| 38 | + ['@babel/preset-env', { |
| 39 | + targets: '> 0.25%, not dead' |
| 40 | + }] |
| 41 | + ], |
| 42 | + plugins: [ |
| 43 | + '@babel/plugin-syntax-dynamic-import', |
| 44 | + ['@babel/plugin-transform-runtime', { |
| 45 | + useESModules: true |
| 46 | + }] |
| 47 | + ] |
| 48 | + }), |
| 49 | + |
| 50 | + !dev && terser({ |
| 51 | + module: true |
| 52 | + }) |
| 53 | + ], |
| 54 | + |
| 55 | + onwarn, |
| 56 | + }, |
| 57 | + |
| 58 | + server: { |
| 59 | + input: config.server.input(), |
| 60 | + output: config.server.output(), |
| 61 | + plugins: [ |
| 62 | + replace({ |
| 63 | + 'process.browser': false, |
| 64 | + 'process.env.NODE_ENV': JSON.stringify(mode) |
| 65 | + }), |
| 66 | + svelte({ |
| 67 | + generate: 'ssr', |
| 68 | + dev |
| 69 | + }), |
| 70 | + resolve(), |
| 71 | + commonjs() |
| 72 | + ], |
| 73 | + external: Object.keys(pkg.dependencies).concat( |
| 74 | + require('module').builtinModules || Object.keys(process.binding('natives')) |
| 75 | + ), |
| 76 | + |
| 77 | + onwarn, |
| 78 | + }, |
| 79 | + |
| 80 | + serviceworker: { |
| 81 | + input: config.serviceworker.input(), |
| 82 | + output: config.serviceworker.output(), |
| 83 | + plugins: [ |
| 84 | + resolve(), |
| 85 | + replace({ |
| 86 | + 'process.browser': true, |
| 87 | + 'process.env.NODE_ENV': JSON.stringify(mode) |
| 88 | + }), |
| 89 | + commonjs(), |
| 90 | + !dev && terser() |
| 91 | + ], |
| 92 | + |
| 93 | + onwarn, |
| 94 | + } |
| 95 | +}; |
0 commit comments