-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
201 lines (182 loc) · 5.63 KB
/
rollup.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import { terser } from 'rollup-plugin-terser'
import alias from '@rollup/plugin-alias'
import commonjs from '@rollup/plugin-commonjs'
import dotenv from 'dotenv'
import fs from 'fs'
import gzip from 'rollup-plugin-gzip'
import html, { makeHtmlAttributes } from '@rollup/plugin-html'
import image from '@rollup/plugin-image'
import json from '@rollup/plugin-json'
import livereload from 'rollup-plugin-livereload'
import path from 'path'
import replace from '@rollup/plugin-replace'
import resolve from '@rollup/plugin-node-resolve'
import serve from 'rollup-plugin-serve'
import styles from 'rollup-plugin-styles'
import sucrase from '@rollup/plugin-sucrase'
import vue from '@vitejs/plugin-vue'
import vue3svg from '@pathscale/vue3-svg-icons'
import vue3uiPurge from '@pathscale/rollup-plugin-vue3-ui-css-purge'
import zlib from 'zlib'
const extensions = ['.ts', '.mjs', '.js', '.vue', '.json']
const aliases = {
'~': path.resolve('src').replace(/\\/g, '/'),
}
// eslint-disable-next-line no-undef -- ignore
const env = dotenv.config({ path: path.join(__dirname, '.env') })
const prod = process.env.NODE_ENV === 'production'
const watch = Boolean(process.env.ROLLUP_WATCH) || Boolean(process.env.LIVERELOAD)
const addVersion = fileName => {
const ver = prod ? env.parsed.VUE_APP_VERSION_NUMBER : Date.now()
const { dir, ext, base } = path.parse(fileName)
if (ext === '.html') {
return fileName
}
const filename = base + `?v=${ver}`
return dir ? `${dir}/${filename}` : filename
}
const template = ({ attributes, files, meta, publicPath, title }) => {
const scripts = (files.js || [])
.map(({ fileName }) => {
const file = addVersion(fileName)
const attrs = makeHtmlAttributes(attributes.script)
return `<script src="${publicPath}${file}"${attrs}></script>`
})
.join('\n')
const links = (files.css || [])
.map(({ fileName }) => {
const file = addVersion(fileName)
const attrs = makeHtmlAttributes(attributes.link)
return `<link href="${publicPath}${file}" rel="stylesheet"${attrs}>`
})
.join('\n')
const metas = meta
.map(input => {
const attrs = makeHtmlAttributes(input)
return `<meta${attrs}>`
})
.join('\n')
return `
<!doctype html>
<html${makeHtmlAttributes(attributes.html)}>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
${metas}
<title>${title}</title>
<link rel="icon" href="favicon.ico">
${links}
</head>
<body>
<div id="app"></div>
${scripts}
</body>
</html>
`
}
const config = [
{
input: 'src/main.ts',
output: [
{
format: 'iife',
file: 'dist/app.js',
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
assetFileNames: '[name][extname]',
},
],
plugins: [
json(),
replace({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.VUE_APP_VERSION_NUMBER': JSON.stringify(env.parsed.VUE_APP_VERSION_NUMBER),
'process.env.VUE_APP_USERNAME': JSON.stringify(env.parsed.VUE_APP_USERNAME),
'process.env.VUE_APP_PASSWORD': JSON.stringify(env.parsed.VUE_APP_PASSWORD),
'process.env.AUTH_SERVER': JSON.stringify(env.parsed.AUTH_SERVER),
'process.env.APP_SERVER': JSON.stringify(env.parsed.APP_SERVER),
__VUE_OPTIONS_API__: false,
__VUE_PROD_DEVTOOLS__: false,
DEBUG: true,
preventAssignment: true,
}),
alias({ entries: aliases }),
resolve({
dedupe: [
'vue',
'@vue/compiler-core',
'@vue/compiler-dom',
'@vue/compiler-sfc',
'@vue/compiler-ssr',
'@vue/reactivity',
'@vue/runtime-core',
'@vue/runtime-dom',
'@vue/shared',
'vuex',
],
preferBuiltins: true,
extensions,
}),
commonjs(),
vue3svg(),
prod && vue3uiPurge({ alias: aliases, debug: false }),
vue({ preprocessStyles: false }),
image({ exclude: /\.svg$/ }),
{
name: 'svg',
load(id) {
const [url] = id.split('?')
if (!/\.svg$/.test(url)) {
return null
}
this.addWatchFile(url)
return fs.readFileSync(url, 'utf8')
},
transform(code, id) {
const [url, query] = id.split('?')
if (!/\.svg$/.test(url)) {
return null
}
if (query !== 'data') {
code = 'data:image/svg+xml;utf8,' + encodeURIComponent(code)
}
return { code: `export default ${JSON.stringify(code)};`, map: { mappings: '' } }
},
},
styles({
mode: 'extract',
url: {
hash: '[name][extname]',
publicPath: env.parsed.BASE_URL,
inline: true,
},
minimize: prod && {
preset: ['default', { discardComments: { removeAll: true } }],
},
}),
sucrase({ exclude: ['**/node_modules/**'], transforms: ['typescript'] }),
prod && terser({ format: { comments: false } }),
prod &&
gzip({
fileName: '.br',
customCompression: content =>
zlib.brotliCompressSync(Buffer.from(content), {
params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 11 },
}),
}),
html({
publicPath: env.parsed.BASE_URL,
title: 'SalesAction',
template,
}),
watch &&
serve({
host: '0.0.0.0',
contentBase: 'dist',
historyApiFallback: true,
port: 5000,
}),
watch && livereload({ watch: 'dist' }),
],
},
]
export default config