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