parent
9da8158ea9
commit
5674634471
2
index.js
2
index.js
|
@ -16,7 +16,7 @@ import compile from './lib/prod.js'
|
||||||
const WORK_SPACE = process.cwd()
|
const WORK_SPACE = process.cwd()
|
||||||
const IS_WINDOWS = process.platform === 'win32'
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
|
|
||||||
const CONFIG_FILE = normalize(join(WORK_SPACE, 'vue.live.js'))
|
const CONFIG_FILE = normalize(join(WORK_SPACE, 'fite.config.js'))
|
||||||
const PROTOCOL = IS_WINDOWS ? 'file://' : ''
|
const PROTOCOL = IS_WINDOWS ? 'file://' : ''
|
||||||
const NODE_VERSION = +process.versions.node.split('.').slice(0, 2).join('.')
|
const NODE_VERSION = +process.versions.node.split('.').slice(0, 2).join('.')
|
||||||
|
|
||||||
|
|
63
lib/dev.js
63
lib/dev.js
|
@ -72,32 +72,47 @@ export default async function createServer(root = '', conf = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pathname) {
|
if (pathname) {
|
||||||
pathname = pathname.split('/')
|
// 这种情况是, 页面是子目录的情况
|
||||||
|
if (pathname.includes('/') && pathname.endsWith('.html')) {
|
||||||
if (pathname[0].endsWith('.html')) {
|
pageName = pathname.slice(0, -5)
|
||||||
pageName = pathname.shift()
|
if (conf.pages[pageName]) {
|
||||||
|
|
||||||
let tmp = pageName.split('.')
|
|
||||||
|
|
||||||
ext = tmp.pop()
|
|
||||||
pageName = tmp.join('.')
|
|
||||||
|
|
||||||
currentPage = pageName
|
|
||||||
pagesDir = dirname(conf.pages[pageName].entry)
|
|
||||||
} else {
|
|
||||||
if (currentPage) {
|
|
||||||
let tmp = pathname.at(-1).split('.')
|
|
||||||
// 修正history路由时的访问
|
|
||||||
ext = tmp.length > 1 ? tmp.pop() : 'html'
|
|
||||||
pageName = currentPage
|
|
||||||
} else {
|
|
||||||
pageName = Object.keys(conf.pages).pop()
|
|
||||||
currentPage = pageName
|
|
||||||
pagesDir = dirname(conf.pages[pageName].entry)
|
|
||||||
ext = 'html'
|
ext = 'html'
|
||||||
|
currentPage = pageName
|
||||||
|
pagesDir = dirname(conf.pages[pageName]?.entry)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pathname = pathname.split('/')
|
||||||
|
|
||||||
|
if (pathname[0].endsWith('.html')) {
|
||||||
|
pageName = pathname.shift()
|
||||||
|
|
||||||
|
let tmp = pageName.split('.')
|
||||||
|
|
||||||
|
ext = tmp.pop()
|
||||||
|
pageName = tmp.join('.')
|
||||||
|
// 页面不存在时输出404, 避免进程崩溃退出
|
||||||
|
if (!conf.pages[pageName]) {
|
||||||
|
res.writeHead(404, 'Not Found')
|
||||||
|
return res.end(`Oops!!! 404 Not Found`)
|
||||||
|
}
|
||||||
|
|
||||||
|
currentPage = pageName
|
||||||
|
pagesDir = dirname(conf.pages[pageName]?.entry)
|
||||||
|
} else {
|
||||||
|
if (currentPage) {
|
||||||
|
let tmp = pathname.at(-1).split('.')
|
||||||
|
// 修正history路由时的访问
|
||||||
|
ext = tmp.length > 1 ? tmp.pop() : 'html'
|
||||||
|
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 {
|
||||||
if (IS_MPA) {
|
if (IS_MPA) {
|
||||||
isIndex = true
|
isIndex = true
|
||||||
|
@ -128,7 +143,7 @@ export default async function createServer(root = '', conf = {}) {
|
||||||
res.setHeader('content-type', MIME_TYPES.html)
|
res.setHeader('content-type', MIME_TYPES.html)
|
||||||
|
|
||||||
let page = conf.pages[pageName]
|
let page = conf.pages[pageName]
|
||||||
let entry = fs.cat(page.entry).toString()
|
let entry = fs.cat(page.entry)?.toString()
|
||||||
let html = fs.cat(join(process.cwd(), 'index.html')).toString()
|
let html = fs.cat(join(process.cwd(), 'index.html')).toString()
|
||||||
|
|
||||||
entry = parseJs(entry, conf.imports, {
|
entry = parseJs(entry, conf.imports, {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "fite",
|
"name": "fite",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.5.0",
|
"version": "0.6.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"fite": "index.js"
|
"fite": "index.js"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue