parent
82d1fc31a6
commit
18072c4887
|
@ -89,12 +89,10 @@ export function parseJs(
|
|||
isBuild
|
||||
) {
|
||||
let fixedStyle = '\n\n'
|
||||
let ASSETS_JS = '/@/'
|
||||
let ASSETS_CSS = '/@/'
|
||||
let ASSETS_DIR = '/@/'
|
||||
|
||||
if (isBuild) {
|
||||
ASSETS_JS = '/assets/js/'
|
||||
ASSETS_CSS = '/assets/css/'
|
||||
ASSETS_DIR = '/assets/' // + (IS_MPA ? 'pages/' : '')
|
||||
}
|
||||
code = Es.transformSync(code).code || ''
|
||||
|
||||
|
@ -105,23 +103,23 @@ 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_DIR))
|
||||
}
|
||||
|
||||
if (!imports[name]) {
|
||||
if (name.startsWith('./') || name.startsWith('../')) {
|
||||
if (IS_ENTRY) {
|
||||
if (IS_MPA) {
|
||||
name = `${currentPage}/` + name
|
||||
name = `pages/${currentPage}/` + name
|
||||
}
|
||||
name = urlJoin(DEPLOY_PATH, ASSETS_JS, name)
|
||||
name = urlJoin(DEPLOY_PATH, ASSETS_DIR, name)
|
||||
}
|
||||
} else if (
|
||||
name.startsWith('/') &&
|
||||
!name.startsWith('//') &&
|
||||
!name.startsWith(urlJoin(DEPLOY_PATH, ASSETS_JS))
|
||||
!name.startsWith(urlJoin(DEPLOY_PATH, ASSETS_DIR))
|
||||
) {
|
||||
name = name.replace(/^\//, urlJoin(DEPLOY_PATH, ASSETS_JS))
|
||||
name = name.replace(/^\//, urlJoin(DEPLOY_PATH, ASSETS_DIR))
|
||||
}
|
||||
|
||||
if (!name.endsWith('.js') && !name.endsWith('.vue')) {
|
||||
|
@ -143,7 +141,7 @@ export function parseJs(
|
|||
name = name.replace(/\.vue$/, '.js')
|
||||
}
|
||||
if (name.startsWith('@/')) {
|
||||
name = name.replace('@/', urlJoin(DEPLOY_PATH, ASSETS_JS))
|
||||
name = name.replace('@/', urlJoin(DEPLOY_PATH, ASSETS_DIR))
|
||||
}
|
||||
return `import('${name}')`
|
||||
})
|
||||
|
@ -166,7 +164,7 @@ export function parseJs(
|
|||
)}'`
|
||||
} else {
|
||||
if (name.startsWith('@/')) {
|
||||
name = name.replace('@/', urlJoin(DEPLOY_PATH, ASSETS_JS))
|
||||
name = name.replace('@/', urlJoin(DEPLOY_PATH, ASSETS_DIR))
|
||||
}
|
||||
//
|
||||
if (!imports[name]) {
|
||||
|
@ -175,14 +173,14 @@ export function parseJs(
|
|||
if (IS_MPA) {
|
||||
name = `${currentPage}/` + name
|
||||
}
|
||||
name = urlJoin(DEPLOY_PATH, ASSETS_JS, name)
|
||||
name = urlJoin(DEPLOY_PATH, ASSETS_DIR, name)
|
||||
}
|
||||
} else if (
|
||||
name.startsWith('/') &&
|
||||
!name.startsWith('//') &&
|
||||
!name.startsWith(urlJoin(DEPLOY_PATH, ASSETS_JS))
|
||||
!name.startsWith(urlJoin(DEPLOY_PATH, ASSETS_DIR))
|
||||
) {
|
||||
name = name.replace(/^\//, urlJoin(DEPLOY_PATH, ASSETS_JS))
|
||||
name = name.replace(/^\//, urlJoin(DEPLOY_PATH, ASSETS_DIR))
|
||||
}
|
||||
|
||||
if (!name.endsWith('.js') && !name.endsWith('.vue')) {
|
||||
|
|
23
lib/dev.js
23
lib/dev.js
|
@ -150,8 +150,7 @@ export default async function createServer(root = '', conf = {}) {
|
|||
|
||||
if (IS_MPA) {
|
||||
if (rpath.startsWith(currentPage)) {
|
||||
rpath = rpath.slice(currentPage.length)
|
||||
file = join(pagesDir, rpath)
|
||||
file = join(pagesDir, rpath.slice(currentPage.length))
|
||||
} else {
|
||||
file = join(SOURCE_DIR, rpath)
|
||||
}
|
||||
|
@ -199,27 +198,25 @@ export default async function createServer(root = '', conf = {}) {
|
|||
|
||||
case 'js':
|
||||
{
|
||||
pathname = pathname.replace(/@\//, '')
|
||||
let rpath = pathname.replace(/@\//, '')
|
||||
let file
|
||||
|
||||
if (IS_MPA) {
|
||||
if (pathname.startsWith(currentPage)) {
|
||||
file = join(pagesDir, pathname.slice(currentPage.length))
|
||||
if (rpath.startsWith(currentPage)) {
|
||||
file = join(pagesDir, rpath.slice(currentPage.length))
|
||||
} else {
|
||||
file = join(pagesDir, pathname)
|
||||
}
|
||||
if (!fs.isfile(file)) {
|
||||
file = join(SOURCE_DIR, pathname)
|
||||
file = join(SOURCE_DIR, rpath)
|
||||
}
|
||||
} else {
|
||||
file = join(SOURCE_DIR, pathname)
|
||||
file = join(SOURCE_DIR, rpath)
|
||||
}
|
||||
|
||||
if (fs.isfile(file)) {
|
||||
code = fs.cat(file)
|
||||
} else if (fs.isfile(join(PUBLIC_DIR, pathname))) {
|
||||
code = fs.cat(join(PUBLIC_DIR, pathname))
|
||||
} else if (fs.isfile(join(PUBLIC_DIR, rpath))) {
|
||||
code = fs.cat(join(PUBLIC_DIR, rpath))
|
||||
} else {
|
||||
friendlyErrors(pathname, ext)
|
||||
friendlyErrors(rpath, ext)
|
||||
res.writeHead(404, 'Not Found')
|
||||
res.end('')
|
||||
return
|
||||
|
|
16
lib/prod.js
16
lib/prod.js
|
@ -49,6 +49,8 @@ export default function compile(root = '', dist = '', conf = {}) {
|
|||
|
||||
console.log(' 解析 %s ...', it.name)
|
||||
|
||||
let pageDir = IS_MPA && currentPage ? `pages/${currentPage}` : ''
|
||||
|
||||
switch (it.ext) {
|
||||
case '.vue':
|
||||
{
|
||||
|
@ -62,12 +64,7 @@ export default function compile(root = '', dist = '', conf = {}) {
|
|||
Es.transform(code, { minify: true }).then(r => {
|
||||
fs.echo(
|
||||
r.code,
|
||||
join(
|
||||
dist,
|
||||
'assets/js/',
|
||||
IS_MPA ? currentPage : '',
|
||||
it.name.replace(/\.vue$/, '.js')
|
||||
)
|
||||
join(dist, 'assets/', pageDir, it.name.replace(/\.vue$/, '.js'))
|
||||
)
|
||||
})
|
||||
}
|
||||
|
@ -84,10 +81,7 @@ export default function compile(root = '', dist = '', conf = {}) {
|
|||
true
|
||||
)
|
||||
Es.transform(code, { minify: true }).then(r => {
|
||||
fs.echo(
|
||||
r.code,
|
||||
join(dist, 'assets/js/', IS_MPA ? currentPage : '', it.name)
|
||||
)
|
||||
fs.echo(r.code, join(dist, 'assets/', pageDir, it.name))
|
||||
})
|
||||
}
|
||||
break
|
||||
|
@ -97,7 +91,7 @@ export default function compile(root = '', dist = '', conf = {}) {
|
|||
{
|
||||
let code = compileScss(it.path)
|
||||
if (!it.name.startsWith('assets')) {
|
||||
it.name = 'assets/js/' + it.name
|
||||
it.name = 'assets/' + it.name
|
||||
}
|
||||
fs.echo(code, join(dist, it.name.replace(/\.scss$/, '.css')))
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "fite",
|
||||
"type": "module",
|
||||
"version": "0.3.5",
|
||||
"version": "0.4.0",
|
||||
"bin": {
|
||||
"fite": "index.js"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue