diff --git a/lib/compile-vue.js b/lib/compile-vue.js index fc0fb42..b8cb504 100644 --- a/lib/compile-vue.js +++ b/lib/compile-vue.js @@ -113,7 +113,7 @@ export function compileScss(file, mini = true) { return scss.compileString(file, { style, ...OPTIONS }).css.trim() } } catch (err) { - console.log('compile scss: ', file) + // console.log('compile scss: ', file) console.error(err) } } @@ -212,7 +212,7 @@ export function parseJs( .replace(/import (["'])(.*?)\1/g, function (m, q, name) { if (name.endsWith('.css') || name.endsWith('.scss')) { if (name.startsWith('@/')) { - name = name.replace('@/', '/') + name = name.replace('@/', urlJoin(DEPLOY_PATH, ASSETS_DIR)) } if (isBuild) { diff --git a/lib/constants.js b/lib/constants.js index 301b85c..f7ef16d 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -4,9 +4,9 @@ * @date 2022/09/06 11:54:56 */ -export const JS_EXP = /]*?>([\w\W]*?)<\/script>/ -export const STYLE_EXP = /]*?)>([\w\W]*?)<\/style>/g -export const HTML_EXP = /]*?>([\w\W]*?)\n<\/template>/ +export const JS_EXP = /(?<=\n|^)]*?>([\w\W]*?)<\/script>/ +export const STYLE_EXP = /(?<=\n|^)]*?)>([\w\W]*?)<\/style>/g +export const HTML_EXP = /(?<=\n|^)]*?>([\w\W]*?)\n<\/template>/ export const V_DEEP = /:deep\(([^)]*?)\)(.*)/ export const CSS_SHEET_EXP = /([%@\w\.,#\-:>\+\~\|\(\)\[\]"'\=\s]+)\{/g diff --git a/lib/prod.js b/lib/prod.js index 6c70955..154d8e0 100644 --- a/lib/prod.js +++ b/lib/prod.js @@ -9,6 +9,7 @@ export default function compile(root = '', dist = '', conf = {}) { const PUBLIC_DIR = join(root, 'public') const DEPLOY_PATH = conf.base || '' // 部署目录, 默认是根目录部署 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 template = fs.cat(join(process.env.PWD, 'index.html')).toString() @@ -20,7 +21,21 @@ export default function compile(root = '', dist = '', conf = {}) { path: it, 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 options = { IS_MPA, currentPage, SOURCE_DIR, DEPLOY_PATH } @@ -113,7 +128,7 @@ export default function compile(root = '', dist = '', conf = {}) { if (fs.isdir(it)) { return } - let idx = list.findIndex(_ => _.path === it) + let idx = list.findIndex(_ => _?.path === it) let name = it.slice(dir.length + 1) let ext = parse(name).ext @@ -121,7 +136,7 @@ export default function compile(root = '', dist = '', conf = {}) { return } - list.splice(idx, 1) + list[idx] = null files.push({ name, @@ -134,6 +149,8 @@ export default function compile(root = '', dist = '', conf = {}) { compileFiles(currentPage, page, files) } + list = list.filter(it => it) + if (IS_MPA) { console.log('\n正在解析公共依赖 ...') compileFiles('', null, list) diff --git a/package.json b/package.json index 13687c3..7fcfc84 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fite", "type": "module", - "version": "0.9.4", + "version": "1.0.0", "bin": { "fite": "index.js" },