修复打包

pull/1/head 1.0.0
yutent 2023-05-15 15:17:55 +08:00
parent 5d9f768f1e
commit 927aaa5bc9
4 changed files with 26 additions and 9 deletions

View File

@ -113,7 +113,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.log('compile scss: ', file)
console.error(err) console.error(err)
} }
} }
@ -212,7 +212,7 @@ export function parseJs(
.replace(/import (["'])(.*?)\1/g, function (m, q, name) { .replace(/import (["'])(.*?)\1/g, function (m, q, name) {
if (name.endsWith('.css') || name.endsWith('.scss')) { if (name.endsWith('.css') || name.endsWith('.scss')) {
if (name.startsWith('@/')) { if (name.startsWith('@/')) {
name = name.replace('@/', '/') name = name.replace('@/', urlJoin(DEPLOY_PATH, ASSETS_DIR))
} }
if (isBuild) { if (isBuild) {

View File

@ -4,9 +4,9 @@
* @date 2022/09/06 11:54:56 * @date 2022/09/06 11:54:56
*/ */
export const JS_EXP = /<script[^>]*?>([\w\W]*?)<\/script>/ export const JS_EXP = /(?<=\n|^)<script[^>]*?>([\w\W]*?)<\/script>/
export const STYLE_EXP = /<style([^>]*?)>([\w\W]*?)<\/style>/g export const STYLE_EXP = /(?<=\n|^)<style([^>]*?)>([\w\W]*?)<\/style>/g
export const HTML_EXP = /<template[^>]*?>([\w\W]*?)\n<\/template>/ export const HTML_EXP = /(?<=\n|^)<template[^>]*?>([\w\W]*?)\n<\/template>/
export const V_DEEP = /:deep\(([^)]*?)\)(.*)/ export const V_DEEP = /:deep\(([^)]*?)\)(.*)/
export const CSS_SHEET_EXP = /([%@\w\.,#\-:>\+\~\|\(\)\[\]"'\=\s]+)\{/g export const CSS_SHEET_EXP = /([%@\w\.,#\-:>\+\~\|\(\)\[\]"'\=\s]+)\{/g

View File

@ -9,6 +9,7 @@ export default function compile(root = '', dist = '', conf = {}) {
const PUBLIC_DIR = join(root, 'public') const PUBLIC_DIR = join(root, 'public')
const DEPLOY_PATH = conf.base || '' // 部署目录, 默认是根目录部署 const DEPLOY_PATH = conf.base || '' // 部署目录, 默认是根目录部署
const IS_MPA = Object.keys(conf.pages).length > 1 const IS_MPA = Object.keys(conf.pages).length > 1
const PAGES_PREFIX = Object.keys(conf.pages).map(it => `pages/${it}/`)
let timeStart = Date.now() let timeStart = Date.now()
let template = fs.cat(join(process.env.PWD, 'index.html')).toString() let template = fs.cat(join(process.env.PWD, 'index.html')).toString()
@ -20,7 +21,21 @@ export default function compile(root = '', dist = '', conf = {}) {
path: it, path: it,
ext: parse(it).ext ext: parse(it).ext
})) }))
.filter(it => fs.isfile(it.path) && it.ext !== '') .filter(it => {
if (fs.isfile(it.path) && it.ext !== '') {
if (IS_MPA && it.name.startsWith('pages/')) {
if (PAGES_PREFIX.some(it => it.startsWith(it.name))) {
return true
} else {
return false
}
}
return true
}
return false
})
let compileFiles = function (currentPage, page, files) { let compileFiles = function (currentPage, page, files) {
let options = { IS_MPA, currentPage, SOURCE_DIR, DEPLOY_PATH } let options = { IS_MPA, currentPage, SOURCE_DIR, DEPLOY_PATH }
@ -113,7 +128,7 @@ export default function compile(root = '', dist = '', conf = {}) {
if (fs.isdir(it)) { if (fs.isdir(it)) {
return return
} }
let idx = list.findIndex(_ => _.path === it) let idx = list.findIndex(_ => _?.path === it)
let name = it.slice(dir.length + 1) let name = it.slice(dir.length + 1)
let ext = parse(name).ext let ext = parse(name).ext
@ -121,7 +136,7 @@ export default function compile(root = '', dist = '', conf = {}) {
return return
} }
list.splice(idx, 1) list[idx] = null
files.push({ files.push({
name, name,
@ -134,6 +149,8 @@ export default function compile(root = '', dist = '', conf = {}) {
compileFiles(currentPage, page, files) compileFiles(currentPage, page, files)
} }
list = list.filter(it => it)
if (IS_MPA) { if (IS_MPA) {
console.log('\n正在解析公共依赖 ...') console.log('\n正在解析公共依赖 ...')
compileFiles('', null, list) compileFiles('', null, list)

View File

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