修复一波bug

pull/1/head
yutent 2023-03-02 16:55:52 +08:00
parent eeb324a247
commit 5497bd18fa
3 changed files with 30 additions and 20 deletions

View File

@ -72,6 +72,7 @@ export function compileScss(file, mini = true) {
return scss.compileString(file, { style, ...OPTIONS }).css.trim()
}
} catch (err) {
console.log('compile scss: ', file)
console.error(err)
}
}
@ -88,6 +89,14 @@ export function parseJs(
isBuild
) {
let fixedStyle = '\n\n'
let ASSETS_JS = '/$ASSETS_JS/'
let ASSETS_CSS = '/$ASSETS_CSS/'
if (isBuild) {
ASSETS_JS = '/assets/js/'
ASSETS_CSS = '/assets/css/'
}
code = Es.transformSync(code).code || ''
return (
code
@ -96,7 +105,7 @@ export function parseJs(
/import ([\w\W]*?) from (["'])(.*?)\2/g,
function (m, alias, q, name) {
if (name.startsWith('@/')) {
name = name.replace('@/', urlJoin(DEPLOY_PATH, '/assets/js/'))
name = name.replace('@/', urlJoin(DEPLOY_PATH, ASSETS_JS))
}
if (!imports[name]) {
@ -105,14 +114,14 @@ export function parseJs(
if (IS_MPA) {
name = `${currentPage}/` + name
}
name = urlJoin(DEPLOY_PATH, '/assets/js/', name)
name = urlJoin(DEPLOY_PATH, ASSETS_JS, name)
}
} else if (
name.startsWith('/') &&
!name.startsWith('//') &&
!name.startsWith(urlJoin(DEPLOY_PATH, '/assets/js/'))
!name.startsWith(urlJoin(DEPLOY_PATH, ASSETS_JS))
) {
name = name.replace(/^\//, urlJoin(DEPLOY_PATH, '/assets/js/'))
name = name.replace(/^\//, urlJoin(DEPLOY_PATH, ASSETS_JS))
}
if (!name.endsWith('.js') && !name.endsWith('.vue')) {
@ -133,6 +142,9 @@ export function parseJs(
if (isBuild) {
name = name.replace(/\.vue$/, '.js')
}
if (name.startsWith('@/')) {
name = name.replace('@/', urlJoin(DEPLOY_PATH, ASSETS_JS))
}
return `import('${name}')`
})
.replace(/import (["'])(.*?)\1/g, function (m, q, name) {
@ -154,7 +166,7 @@ export function parseJs(
)}'`
} else {
if (name.startsWith('@/')) {
name = name.replace('@/', urlJoin(DEPLOY_PATH, '/assets/js/'))
name = name.replace('@/', urlJoin(DEPLOY_PATH, ASSETS_JS))
}
//
if (!imports[name]) {
@ -163,14 +175,14 @@ export function parseJs(
if (IS_MPA) {
name = `${currentPage}/` + name
}
name = urlJoin(DEPLOY_PATH, '/assets/js/', name)
name = urlJoin(DEPLOY_PATH, ASSETS_JS, name)
}
} else if (
name.startsWith('/') &&
!name.startsWith('//') &&
!name.startsWith(urlJoin(DEPLOY_PATH, '/assets/js/'))
!name.startsWith(urlJoin(DEPLOY_PATH, ASSETS_JS))
) {
name = name.replace(/^\//, urlJoin(DEPLOY_PATH, '/assets/js/'))
name = name.replace(/^\//, urlJoin(DEPLOY_PATH, ASSETS_JS))
}
if (!name.endsWith('.js') && !name.endsWith('.vue')) {
@ -198,7 +210,7 @@ export function compileVue(file, imports, options = {}, isBuild) {
let js = code.match(JS_EXP)
let scss = [...code.matchAll(STYLE_EXP)]
let html = code.match(HTML_EXP)
let html = code.match(HTML_EXP) || ['', '']
let hash = md5(file)
let scopeId = 'data-' + hash
@ -232,7 +244,7 @@ export function compileVue(file, imports, options = {}, isBuild) {
isCustomElement: tag => tag.startsWith('wc-')
}).code.replace('export function render', 'function render')
output += html
output += html + '\n\n'
if (CACHE[file]) {
CACHE[file] = {

View File

@ -84,7 +84,9 @@ export default async function createServer(root = '', conf = {}) {
pagesDir = dirname(conf.pages[pageName].entry)
} else {
if (currentPage) {
ext = pathname.at(-1).split('.').pop()
let tmp = pathname.at(-1).split('.')
// 修正history路由时的访问
ext = tmp.length > 1 ? tmp.pop() : 'html'
pageName = currentPage
} else {
pageName = Object.keys(conf.pages).pop()
@ -104,10 +106,6 @@ export default async function createServer(root = '', conf = {}) {
ext = 'html'
}
}
// 修正history路由时的访问
if (pathname === ext) {
ext = 'html'
}
for (let k in COMMON_HEADERS) {
res.setHeader(k, COMMON_HEADERS[k])
@ -145,7 +143,7 @@ export default async function createServer(root = '', conf = {}) {
case 'vue':
{
let rpath = pathname.replace(/^assets\/js\//, '')
let rpath = pathname.replace(/\$ASSETS_JS\//, '')
let file
if (IS_MPA) {
@ -194,8 +192,8 @@ export default async function createServer(root = '', conf = {}) {
let file = join(
SOURCE_DIR,
pathname
.replace(/^assets\/css\//, '')
.replace(/^assets\/js\//, '')
.replace(/\$ASSETS_CSS\//, '')
.replace(/\$ASSETS_JS\//, '')
)
code = compileScss(file)
res.setHeader('content-type', MIME_TYPES.css)
@ -204,7 +202,7 @@ export default async function createServer(root = '', conf = {}) {
case 'js':
{
pathname = pathname.replace(/^assets\/js\//, '')
pathname = pathname.replace(/\$ASSETS_JS\//, '')
let file
if (IS_MPA) {
if (pathname.startsWith(currentPage)) {

View File

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