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