Skip to content

Commit 11f713a

Browse files
author
Loïc Mangeonjean
committed
fix(demo): prevent vite from transforming html asset files
1 parent 5f337c1 commit 11f713a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

demo/vite.config.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineConfig } from 'vite'
22
import * as fs from 'fs'
33
import url from 'url'
4+
import path from 'path'
45

56
const cdnDomain = 'http://127.0.0.2:5173'
67

@@ -21,6 +22,27 @@ export default defineConfig({
2122
next()
2223
})
2324
}
25+
},
26+
{
27+
name: 'force-prevent-transform-assets',
28+
apply: 'serve',
29+
configureServer (server) {
30+
return () => {
31+
server.middlewares.use(async (req, res, next) => {
32+
if (req.originalUrl != null) {
33+
const pathname = new URL(req.originalUrl, import.meta.url).pathname
34+
if (pathname.endsWith('.html')) {
35+
res.setHeader('Content-Type', 'text/html')
36+
res.writeHead(200)
37+
res.write(fs.readFileSync(path.join(__dirname, pathname)))
38+
res.end()
39+
}
40+
}
41+
42+
next()
43+
})
44+
}
45+
}
2446
}
2547
],
2648
optimizeDeps: {

0 commit comments

Comments
 (0)