开发模式支持History路由
parent
a961c52c05
commit
96bee5184a
13
lib/dev.js
13
lib/dev.js
|
@ -40,7 +40,7 @@ export default function createServer(root = '', conf = {}) {
|
||||||
WEB_SERVER.createServer(SERVER_OPTIONS, function (req, res) {
|
WEB_SERVER.createServer(SERVER_OPTIONS, function (req, res) {
|
||||||
let pathname = parse(req.url.slice(1)).pathname
|
let pathname = parse(req.url.slice(1)).pathname
|
||||||
let pageName = '',
|
let pageName = '',
|
||||||
isIndex = false
|
isIndex = false // 是否渲染目录页
|
||||||
let ext
|
let ext
|
||||||
|
|
||||||
if (pathname) {
|
if (pathname) {
|
||||||
|
@ -57,8 +57,15 @@ export default function createServer(root = '', conf = {}) {
|
||||||
currentPage = pageName
|
currentPage = pageName
|
||||||
pagesDir = dirname(conf.pages[pageName].entry)
|
pagesDir = dirname(conf.pages[pageName].entry)
|
||||||
} else {
|
} else {
|
||||||
|
if (currentPage) {
|
||||||
ext = pathname.at(-1).split('.').pop()
|
ext = pathname.at(-1).split('.').pop()
|
||||||
pageName = currentPage
|
pageName = currentPage
|
||||||
|
} else {
|
||||||
|
pageName = Object.keys(conf.pages).pop()
|
||||||
|
currentPage = pageName
|
||||||
|
pagesDir = dirname(conf.pages[pageName].entry)
|
||||||
|
ext = 'html'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pathname = pathname.join('/')
|
pathname = pathname.join('/')
|
||||||
} else {
|
} else {
|
||||||
|
@ -71,6 +78,10 @@ export default function createServer(root = '', conf = {}) {
|
||||||
ext = 'html'
|
ext = 'html'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 修正history路由时的访问
|
||||||
|
if (pathname === ext) {
|
||||||
|
ext = 'html'
|
||||||
|
}
|
||||||
|
|
||||||
for (let k in COMMON_HEADERS) {
|
for (let k in COMMON_HEADERS) {
|
||||||
res.setHeader(k, COMMON_HEADERS[k])
|
res.setHeader(k, COMMON_HEADERS[k])
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
{
|
{
|
||||||
"name": "@bytedo/vue-live",
|
"name": "@bytedo/vue-live",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.0.13",
|
"version": "0.0.14",
|
||||||
"bin": {
|
"bin": {
|
||||||
"vue-live": "index.js"
|
"vue-live": "index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@bytedo/sass": "^1.54.8",
|
"@bytedo/sass": "^1.54.8",
|
||||||
|
"chokidar": "^3.5.3",
|
||||||
"esbuild": "^0.15.13",
|
"esbuild": "^0.15.13",
|
||||||
"iofs": "^1.5.2"
|
"iofs": "^1.5.2"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue