forked from Shenmin-Z/srt-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
63 lines (60 loc) · 1.56 KB
/
vite.config.ts
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
import { defineConfig, Plugin, ResolvedConfig, build } from 'vite'
import react from '@vitejs/plugin-react'
import { readFileSync } from 'fs'
import { resolve } from 'path'
const SWPlugin = (): Plugin => {
let config: ResolvedConfig
return {
name: 'vite-plugin-sw-middleware',
config(config, env) {
if (env.command === 'build') {
return {
...config,
build: {
rollupOptions: {
output: {
entryFileNames: '[name].js',
assetFileNames: '[name][extname]',
chunkFileNames: 'common.js',
manualChunks: undefined,
},
},
},
}
} else {
return config
}
},
configResolved(resolvedConfig) {
config = resolvedConfig
},
configureServer({ middlewares }) {
// build({
// build: {
// rollupOptions: {
// input: 'sw/sw.ts',
// output: {
// entryFileNames: `[name].js`,
// manualChunks: undefined,
// },
// },
// minify: false,
// watch: {},
// },
// })
middlewares.use((req, res, next) => {
if (req.originalUrl === config.base + 'sw.js') {
const sw = readFileSync(resolve(__dirname, 'dist/sw.js'))
res.setHeader('Content-Type', 'text/javascript')
res.end(sw)
} else {
next()
}
})
},
}
}
export default defineConfig({
plugins: [react(), SWPlugin()],
base: '/srt-player/',
})