fixed bug
parent
c9bdc6c2f3
commit
c1ccba6103
|
@ -8,6 +8,7 @@ import fs from 'iofs'
|
|||
import scss from '@bytedo/sass'
|
||||
import { createHash } from 'crypto'
|
||||
import Es from 'esbuild'
|
||||
import { resolve } from 'path'
|
||||
|
||||
import {
|
||||
JS_EXP,
|
||||
|
@ -82,7 +83,7 @@ export function compileScss(file, mini = true) {
|
|||
export function parseJs(
|
||||
code = '',
|
||||
imports,
|
||||
{ IS_MPA, currentPage } = {},
|
||||
{ IS_MPA, currentPage, IS_ENTRY } = {},
|
||||
isBuild
|
||||
) {
|
||||
let fixedStyle = '\n\n'
|
||||
|
@ -97,9 +98,12 @@ export function parseJs(
|
|||
}
|
||||
|
||||
if (!imports[name]) {
|
||||
if (name.startsWith('./')) {
|
||||
if (IS_MPA) {
|
||||
name += `${currentPage}/`
|
||||
if (name.startsWith('./') || name.startsWith('../')) {
|
||||
if (IS_ENTRY) {
|
||||
if (IS_MPA) {
|
||||
name = `${currentPage}/` + name
|
||||
}
|
||||
name = resolve('/assets/js/', name)
|
||||
}
|
||||
} else if (
|
||||
name.startsWith('/') &&
|
||||
|
@ -152,10 +156,26 @@ export function parseJs(
|
|||
}
|
||||
//
|
||||
if (!imports[name]) {
|
||||
if (name.startsWith('./') || name.startsWith('../')) {
|
||||
if (IS_ENTRY) {
|
||||
if (IS_MPA) {
|
||||
name = `${currentPage}/` + name
|
||||
}
|
||||
name = resolve('/assets/js/', name)
|
||||
}
|
||||
} else if (
|
||||
name.startsWith('/') &&
|
||||
!name.startsWith('//') &&
|
||||
!name.startsWith('/assets/js/')
|
||||
) {
|
||||
name = name.replace(/^\//, '/assets/js/')
|
||||
}
|
||||
|
||||
if (!name.endsWith('.js') && !name.endsWith('.vue')) {
|
||||
name += '.js'
|
||||
}
|
||||
}
|
||||
|
||||
return `import '${name}'`
|
||||
}
|
||||
}) + fixedStyle
|
||||
|
|
|
@ -117,7 +117,11 @@ export default async function createServer(root = '', conf = {}) {
|
|||
let entry = fs.cat(page.entry).toString()
|
||||
let html = fs.cat(join(process.cwd(), 'index.html')).toString()
|
||||
|
||||
entry = parseJs(entry, conf.imports, { IS_MPA, currentPage })
|
||||
entry = parseJs(entry, conf.imports, {
|
||||
IS_MPA,
|
||||
currentPage,
|
||||
IS_ENTRY: true
|
||||
})
|
||||
|
||||
code = parseHtml(html, { page, imports: conf.imports, entry })
|
||||
}
|
||||
|
|
|
@ -35,7 +35,12 @@ export default function compile(root = '', dist = '', conf = {}) {
|
|||
// 入口文件, 特殊处理
|
||||
if (it.path === page.entry) {
|
||||
let entry = fs.cat(page.entry).toString()
|
||||
entry = parseJs(entry, conf.imports, { IS_MPA, currentPage }, true)
|
||||
entry = parseJs(
|
||||
entry,
|
||||
conf.imports,
|
||||
{ IS_MPA, currentPage, IS_ENTRY: true },
|
||||
true
|
||||
)
|
||||
|
||||
let code = parseHtml(html, { page, imports: conf.imports, entry }, true)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@bytedo/vue-live",
|
||||
"type": "module",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.7",
|
||||
"bin": {
|
||||
"vue-live": "index.js"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue