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

View File

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

View File

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