1
|
|
|
/* eslint-disable */ |
2
|
|
|
import path from 'path'; |
3
|
|
|
import dotenv from 'dotenv'; |
4
|
|
|
import resolve from '@rollup/plugin-node-resolve'; |
5
|
|
|
import replace from '@rollup/plugin-replace'; |
6
|
|
|
import alias from '@rollup/plugin-alias'; |
7
|
|
|
import commonjs from '@rollup/plugin-commonjs'; |
8
|
|
|
import json from '@rollup/plugin-json'; |
9
|
|
|
import svelte from 'rollup-plugin-svelte'; |
10
|
|
|
import babel from 'rollup-plugin-babel'; |
11
|
|
|
import {terser} from 'rollup-plugin-terser'; |
12
|
|
|
import config from 'sapper/config/rollup.js'; |
13
|
|
|
import pkg from './package.json'; |
14
|
|
|
|
15
|
|
|
dotenv.config(); |
16
|
|
|
|
17
|
|
|
const mode = process.env.NODE_ENV; |
18
|
|
|
const dev = mode === 'development'; |
19
|
|
|
const legacy = !!process.env.SAPPER_LEGACY_BUILD; |
20
|
|
|
|
21
|
|
|
const onwarn = (warning, onwarn) => |
22
|
|
|
(warning.code === 'CIRCULAR_DEPENDENCY' && |
23
|
|
|
/[/\\]@sapper[/\\]/.test(warning.message)) || |
24
|
|
|
onwarn(warning); |
25
|
|
|
const dedupe = (importee) => |
26
|
|
|
importee === 'svelte' || importee.startsWith('svelte/'); |
27
|
|
|
|
28
|
|
|
const aliases = [ |
29
|
|
|
{ find: 'src', replacement: path.resolve(__dirname, 'src') }, |
30
|
|
|
{ find: 'components', replacement: path.resolve(__dirname, 'src/components') }, |
31
|
|
|
{ find: 'normalizer', replacement: path.resolve(__dirname, 'src/normalizer') }, |
32
|
|
|
{ find: 'utils', replacement: path.resolve(__dirname, 'src/utils') }, |
33
|
|
|
{ find: 'store', replacement: path.resolve(__dirname, 'src/store') }, |
34
|
|
|
{ find: 'constants', replacement: path.resolve(__dirname, 'src/constants') }, |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
const environmentVariables = { |
38
|
|
|
'process.env.CLIENT_API_URL': JSON.stringify(process.env.CLIENT_API_URL), |
39
|
|
|
'process.env.CLIENT_API_URL_SSR': JSON.stringify(process.env.CLIENT_API_URL_SSR), |
40
|
|
|
}; |
41
|
|
|
|
42
|
|
|
export default { |
43
|
|
|
client: { |
44
|
|
|
input: config.client.input(), |
45
|
|
|
output: config.client.output(), |
46
|
|
|
plugins: [ |
47
|
|
|
replace({ |
48
|
|
|
'process.browser': true, |
49
|
|
|
'process.env.NODE_ENV': JSON.stringify(mode), |
50
|
|
|
...environmentVariables |
51
|
|
|
}), |
52
|
|
|
alias({ entries: aliases }), |
53
|
|
|
svelte({ |
54
|
|
|
dev, |
55
|
|
|
hydratable: true, |
56
|
|
|
emitCss: true |
57
|
|
|
}), |
58
|
|
|
resolve({ |
59
|
|
|
browser: true, |
60
|
|
|
dedupe |
61
|
|
|
}), |
62
|
|
|
json(), |
63
|
|
|
commonjs(), |
64
|
|
|
|
65
|
|
|
legacy && |
66
|
|
|
babel({ |
67
|
|
|
extensions: ['.js', '.mjs', '.html', '.svelte'], |
68
|
|
|
runtimeHelpers: true, |
69
|
|
|
exclude: ['node_modules/@babel/**'], |
70
|
|
|
presets: [ |
71
|
|
|
[ |
72
|
|
|
'@babel/preset-env', |
73
|
|
|
{ |
74
|
|
|
targets: '> 0.25%, not dead' |
75
|
|
|
} |
76
|
|
|
] |
77
|
|
|
], |
78
|
|
|
plugins: [ |
79
|
|
|
'@babel/plugin-syntax-dynamic-import', |
80
|
|
|
[ |
81
|
|
|
'@babel/plugin-transform-runtime', |
82
|
|
|
{ |
83
|
|
|
useESModules: true |
84
|
|
|
} |
85
|
|
|
] |
86
|
|
|
] |
87
|
|
|
}), |
88
|
|
|
|
89
|
|
|
!dev && |
90
|
|
|
terser({ |
91
|
|
|
module: true |
92
|
|
|
}) |
93
|
|
|
], |
94
|
|
|
|
95
|
|
|
context: 'this', |
96
|
|
|
onwarn |
97
|
|
|
}, |
98
|
|
|
|
99
|
|
|
server: { |
100
|
|
|
input: config.server.input(), |
101
|
|
|
output: config.server.output(), |
102
|
|
|
plugins: [ |
103
|
|
|
replace({ |
104
|
|
|
'process.browser': false, |
105
|
|
|
'process.env.NODE_ENV': JSON.stringify(mode), |
106
|
|
|
...environmentVariables, |
107
|
|
|
}), |
108
|
|
|
svelte({ |
109
|
|
|
generate: 'ssr', |
110
|
|
|
dev |
111
|
|
|
}), |
112
|
|
|
resolve({ |
113
|
|
|
dedupe |
114
|
|
|
}), |
115
|
|
|
json(), |
116
|
|
|
commonjs(), |
117
|
|
|
alias({ entries: aliases }), |
118
|
|
|
], |
119
|
|
|
external: Object.keys(pkg.dependencies).concat( |
120
|
|
|
require('module').builtinModules || |
121
|
|
|
Object.keys(process.binding('natives')) |
122
|
|
|
), |
123
|
|
|
|
124
|
|
|
onwarn |
125
|
|
|
}, |
126
|
|
|
|
127
|
|
|
serviceworker: { |
128
|
|
|
input: config.serviceworker.input(), |
129
|
|
|
output: config.serviceworker.output(), |
130
|
|
|
plugins: [ |
131
|
|
|
resolve(), |
132
|
|
|
replace({ |
133
|
|
|
'process.browser': true, |
134
|
|
|
'process.env.NODE_ENV': JSON.stringify(mode) |
135
|
|
|
}), |
136
|
|
|
commonjs(), |
137
|
|
|
!dev && terser() |
138
|
|
|
], |
139
|
|
|
|
140
|
|
|
onwarn |
141
|
|
|
} |
142
|
|
|
}; |
143
|
|
|
|