diff --git a/index.js b/index.js index 77d1d58..298c346 100755 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ import fs from 'iofs' import { join, normalize } from 'path' +import { red, blue } from 'kolorist' import createServer from './lib/dev.js' import compile from './lib/prod.js' @@ -17,9 +18,21 @@ const IS_WINDOWS = process.platform === 'win32' const CONFIG_FILE = normalize(join(WORK_SPACE, 'vue.live.js')) const PROTOCOL = IS_WINDOWS ? 'file://' : '' +const NODE_VERSION = +process.versions.node.split('.').slice(0, 2).join('.') let args = process.argv.slice(2) +if (NODE_VERSION < 16.6) { + console.log(red('Error: 你当前的环境不满足 Vue-live 构建工具的要求')) + console.log( + 'Vue-live 需要Node.js版本在 %s 以上, \n你当前的Node.js版本为: ', + blue('v16.6.0'), + red(process.version), + '\n\n' + ) + process.exit() +} + switch (args[0]) { case 'dev': import(PROTOCOL + CONFIG_FILE) diff --git a/lib/prod.js b/lib/prod.js index 2d17573..612295c 100644 --- a/lib/prod.js +++ b/lib/prod.js @@ -113,36 +113,39 @@ export default function compile(root = '', dist = '', conf = {}) { for (let currentPage in conf.pages) { let page = conf.pages[currentPage] let dir = dirname(page.entry) + let files = list + if (IS_MPA) { + files = [] + fs.ls(dir, true).forEach(it => { + if (fs.isdir(it)) { + return + } + let idx = list.findIndex(_ => _.path === it) + list.splice(idx, 1) - let files = [] - - fs.ls(dir, true).forEach(it => { - if (fs.isdir(it)) { - return - } - let idx = list.findIndex(_ => _.path === it) - list.splice(idx, 1) - files.push({ - name: it.slice(dir.length + 1), - path: it, - ext: parse(it).ext + files.push({ + name: it.slice(dir.length + 1), + path: it, + ext: parse(it).ext + }) }) - }) - + } console.log('正在生成 %s ...', `${currentPage}.html`) compileFiles(currentPage, page, files) } - console.log('正在解析公共依赖 ...') - compileFiles('', null, list) + if (IS_MPA) { + console.log('\n正在解析公共依赖 ...') + compileFiles('', null, list) + } // if (fs.isdir(PUBLIC_DIR)) { - console.log('正在处理静态资源 ...') + console.log('\n正在处理静态资源 ...') fs.ls(PUBLIC_DIR, true).forEach(it => { if (fs.isfile(it)) { let name = it.slice(PUBLIC_DIR.length + 1) - console.log(' 正在复制 %s ...', name) + console.log(' 复制 %s ...', name) fs.cp(it, join(dist, name)) } }) diff --git a/package.json b/package.json index 4ef5b13..0e044ae 100644 --- a/package.json +++ b/package.json @@ -12,5 +12,8 @@ "iofs": "^1.5.2", "kolorist": "^1.6.0", "ws": "^8.12.0" + }, + "engines": { + "node": "^16.6.0" } }