Passed
Push — master ( 085900...85d83b )
by Mathieu
227:05 queued 225:41
created

client/rollup.config.js   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 114
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 81
mnd 0
bc 0
fnc 2
dl 0
loc 114
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
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) =>
15
  (warning.code === 'CIRCULAR_DEPENDENCY' &&
16
    /[/\\]@sapper[/\\]/.test(warning.message)) ||
17
  onwarn(warning);
18
const dedupe = importee =>
19
  importee === 'svelte' || importee.startsWith('svelte/');
20
21
export default {
22
  client: {
23
    input: config.client.input(),
24
    output: config.client.output(),
25
    plugins: [
26
      replace({
27
        'process.browser': true,
28
        'process.env.NODE_ENV': JSON.stringify(mode)
29
      }),
30
      svelte({
31
        dev,
32
        hydratable: true,
33
        emitCss: true
34
      }),
35
      resolve({
36
        browser: true,
37
        dedupe
38
      }),
39
      commonjs(),
40
41
      legacy &&
42
        babel({
43
          extensions: ['.js', '.mjs', '.html', '.svelte'],
44
          runtimeHelpers: true,
45
          exclude: ['node_modules/@babel/**'],
46
          presets: [
47
            [
48
              '@babel/preset-env',
49
              {
50
                targets: '> 0.25%, not dead'
51
              }
52
            ]
53
          ],
54
          plugins: [
55
            '@babel/plugin-syntax-dynamic-import',
56
            [
57
              '@babel/plugin-transform-runtime',
58
              {
59
                useESModules: true
60
              }
61
            ]
62
          ]
63
        }),
64
65
      !dev &&
66
        terser({
67
          module: true
68
        })
69
    ],
70
71
    onwarn
72
  },
73
74
  server: {
75
    input: config.server.input(),
76
    output: config.server.output(),
77
    plugins: [
78
      replace({
79
        'process.browser': false,
80
        'process.env.NODE_ENV': JSON.stringify(mode)
81
      }),
82
      svelte({
83
        generate: 'ssr',
84
        dev
85
      }),
86
      resolve({
87
        dedupe
88
      }),
89
      commonjs()
90
    ],
91
    external: Object.keys(pkg.dependencies).concat(
92
      require('module').builtinModules ||
93
        Object.keys(process.binding('natives'))
94
    ),
95
96
    onwarn
97
  },
98
99
  serviceworker: {
100
    input: config.serviceworker.input(),
101
    output: config.serviceworker.output(),
102
    plugins: [
103
      resolve(),
104
      replace({
105
        'process.browser': true,
106
        'process.env.NODE_ENV': JSON.stringify(mode)
107
      }),
108
      commonjs(),
109
      !dev && terser()
110
    ],
111
112
    onwarn
113
  }
114
};
115