增加Node.js版本判断;优化打包

pull/1/head
yutent 2023-02-24 16:08:18 +08:00
parent 69fc5f5415
commit b864d42f0c
3 changed files with 37 additions and 18 deletions

View File

@ -8,6 +8,7 @@
import fs from 'iofs' import fs from 'iofs'
import { join, normalize } from 'path' import { join, normalize } from 'path'
import { red, blue } from 'kolorist'
import createServer from './lib/dev.js' import createServer from './lib/dev.js'
import compile from './lib/prod.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 CONFIG_FILE = normalize(join(WORK_SPACE, 'vue.live.js'))
const PROTOCOL = IS_WINDOWS ? 'file://' : '' const PROTOCOL = IS_WINDOWS ? 'file://' : ''
const NODE_VERSION = +process.versions.node.split('.').slice(0, 2).join('.')
let args = process.argv.slice(2) 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]) { switch (args[0]) {
case 'dev': case 'dev':
import(PROTOCOL + CONFIG_FILE) import(PROTOCOL + CONFIG_FILE)

View File

@ -113,36 +113,39 @@ export default function compile(root = '', dist = '', conf = {}) {
for (let currentPage in conf.pages) { for (let currentPage in conf.pages) {
let page = conf.pages[currentPage] let page = conf.pages[currentPage]
let dir = dirname(page.entry) 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 = [] files.push({
name: it.slice(dir.length + 1),
fs.ls(dir, true).forEach(it => { path: it,
if (fs.isdir(it)) { ext: parse(it).ext
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
}) })
}) }
console.log('正在生成 %s ...', `${currentPage}.html`) console.log('正在生成 %s ...', `${currentPage}.html`)
compileFiles(currentPage, page, files) compileFiles(currentPage, page, files)
} }
console.log('正在解析公共依赖 ...') if (IS_MPA) {
compileFiles('', null, list) console.log('\n正在解析公共依赖 ...')
compileFiles('', null, list)
}
// //
if (fs.isdir(PUBLIC_DIR)) { if (fs.isdir(PUBLIC_DIR)) {
console.log('正在处理静态资源 ...') console.log('\n正在处理静态资源 ...')
fs.ls(PUBLIC_DIR, true).forEach(it => { fs.ls(PUBLIC_DIR, true).forEach(it => {
if (fs.isfile(it)) { if (fs.isfile(it)) {
let name = it.slice(PUBLIC_DIR.length + 1) let name = it.slice(PUBLIC_DIR.length + 1)
console.log(' 正在复制 %s ...', name) console.log(' 复制 %s ...', name)
fs.cp(it, join(dist, name)) fs.cp(it, join(dist, name))
} }
}) })

View File

@ -12,5 +12,8 @@
"iofs": "^1.5.2", "iofs": "^1.5.2",
"kolorist": "^1.6.0", "kolorist": "^1.6.0",
"ws": "^8.12.0" "ws": "^8.12.0"
},
"engines": {
"node": "^16.6.0"
} }
} }