配置文件名更换为fite.config.js; 支持页面为二级目录

pull/1/head 0.6.0
yutent 2023-04-20 18:56:01 +08:00
parent 9da8158ea9
commit 5674634471
3 changed files with 41 additions and 26 deletions

View File

@ -16,7 +16,7 @@ import compile from './lib/prod.js'
const WORK_SPACE = process.cwd()
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 NODE_VERSION = +process.versions.node.split('.').slice(0, 2).join('.')

View File

@ -72,32 +72,47 @@ export default async function createServer(root = '', conf = {}) {
}
if (pathname) {
pathname = pathname.split('/')
if (pathname[0].endsWith('.html')) {
pageName = pathname.shift()
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)
// 这种情况是, 页面是子目录的情况
if (pathname.includes('/') && pathname.endsWith('.html')) {
pageName = pathname.slice(0, -5)
if (conf.pages[pageName]) {
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 {
if (IS_MPA) {
isIndex = true
@ -128,7 +143,7 @@ export default async function createServer(root = '', conf = {}) {
res.setHeader('content-type', MIME_TYPES.html)
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()
entry = parseJs(entry, conf.imports, {

View File

@ -1,7 +1,7 @@
{
"name": "fite",
"type": "module",
"version": "0.5.0",
"version": "0.6.0",
"bin": {
"fite": "index.js"
},