parent
f28212f933
commit
b08b5c9172
|
@ -0,0 +1,10 @@
|
||||||
|
jsxBracketSameLine: true
|
||||||
|
jsxSingleQuote: true
|
||||||
|
semi: false
|
||||||
|
singleQuote: true
|
||||||
|
printWidth: 80
|
||||||
|
useTabs: false
|
||||||
|
tabWidth: 2
|
||||||
|
trailingComma: none
|
||||||
|
bracketSpacing: true
|
||||||
|
arrowParens: avoid
|
9
index.js
9
index.js
|
@ -21,6 +21,8 @@ const PROTOCOL = IS_WINDOWS ? 'file://' : ''
|
||||||
const NODE_VERSION = +process.versions.node.split('.').slice(0, 2).join('.')
|
const NODE_VERSION = +process.versions.node.split('.').slice(0, 2).join('.')
|
||||||
|
|
||||||
let args = process.argv.slice(2)
|
let args = process.argv.slice(2)
|
||||||
|
let mode = args.shift() || 'prod'
|
||||||
|
let clean = args.shift() !== '--no-clean'
|
||||||
|
|
||||||
if (NODE_VERSION < 16.6) {
|
if (NODE_VERSION < 16.6) {
|
||||||
console.log(red('Error: 你当前的环境不满足 Vue-live 构建工具的要求'))
|
console.log(red('Error: 你当前的环境不满足 Vue-live 构建工具的要求'))
|
||||||
|
@ -33,7 +35,7 @@ if (NODE_VERSION < 16.6) {
|
||||||
process.exit()
|
process.exit()
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (args[0]) {
|
switch (mode) {
|
||||||
case 'dev':
|
case 'dev':
|
||||||
import(PROTOCOL + CONFIG_FILE)
|
import(PROTOCOL + CONFIG_FILE)
|
||||||
.then(function (conf) {
|
.then(function (conf) {
|
||||||
|
@ -48,10 +50,9 @@ switch (args[0]) {
|
||||||
import(PROTOCOL + CONFIG_FILE)
|
import(PROTOCOL + CONFIG_FILE)
|
||||||
.then(function (conf) {
|
.then(function (conf) {
|
||||||
let dist = conf.buildDir || 'dist'
|
let dist = conf.buildDir || 'dist'
|
||||||
if (fs.isdir(dist)) {
|
if (clean && fs.isdir(dist)) {
|
||||||
fs.rm(dist, true)
|
|
||||||
}
|
|
||||||
fs.mkdir(dist)
|
fs.mkdir(dist)
|
||||||
|
}
|
||||||
compile(WORK_SPACE, dist, conf.default)
|
compile(WORK_SPACE, dist, conf.default)
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import http from 'http'
|
import http from 'http'
|
||||||
import https from 'https'
|
import https from 'https'
|
||||||
import fs from 'iofs'
|
import fs from 'iofs'
|
||||||
import { join, resolve, dirname } from 'path'
|
import { join, dirname } from 'path'
|
||||||
import { parse } from 'url'
|
import { parse } from 'url'
|
||||||
import socket from './ws.js'
|
import socket from './ws.js'
|
||||||
import chokidar from 'chokidar'
|
import chokidar from 'chokidar'
|
||||||
import { red, cyan, blue } from 'kolorist'
|
import { red } from 'kolorist'
|
||||||
|
|
||||||
import { friendlyErrors } from './utils.js'
|
import { friendlyErrors } from './utils.js'
|
||||||
|
|
||||||
|
|
40
lib/prod.js
40
lib/prod.js
|
@ -1,10 +1,8 @@
|
||||||
import fs from 'iofs'
|
import fs from 'iofs'
|
||||||
import { join, resolve, dirname, parse } from 'path'
|
import { join, dirname, parse } from 'path'
|
||||||
import Es from 'esbuild'
|
import Es from 'esbuild'
|
||||||
import { compileScss, parseJs, compileVue, parseHtml } from './compile-vue.js'
|
import { compileScss, parseJs, compileVue, parseHtml } from './compile-vue.js'
|
||||||
|
|
||||||
const noc = Buffer.from('')
|
|
||||||
|
|
||||||
export default function compile(root = '', dist = '', conf = {}) {
|
export default function compile(root = '', dist = '', conf = {}) {
|
||||||
//
|
//
|
||||||
const SOURCE_DIR = join(root, 'src')
|
const SOURCE_DIR = join(root, 'src')
|
||||||
|
@ -104,6 +102,24 @@ export default function compile(root = '', dist = '', conf = {}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 优先处理静态目录, 之后的源码目录中, 以便如果有产生相同的文件名, 则覆盖静态目录中的文件
|
||||||
|
if (fs.isdir(PUBLIC_DIR)) {
|
||||||
|
console.log('\n正在处理静态资源 ...')
|
||||||
|
fs.ls(PUBLIC_DIR, true).forEach(it => {
|
||||||
|
let ext = parse(it).ext
|
||||||
|
|
||||||
|
if (ext === '') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.isfile(it)) {
|
||||||
|
let name = it.slice(PUBLIC_DIR.length + 1)
|
||||||
|
console.log(' 复制 %s ...', name)
|
||||||
|
fs.cp(it, join(dist, name))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -140,23 +156,5 @@ export default function compile(root = '', dist = '', conf = {}) {
|
||||||
compileFiles('', null, list)
|
compileFiles('', null, list)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
if (fs.isdir(PUBLIC_DIR)) {
|
|
||||||
console.log('\n正在处理静态资源 ...')
|
|
||||||
fs.ls(PUBLIC_DIR, true).forEach(it => {
|
|
||||||
let ext = parse(it).ext
|
|
||||||
|
|
||||||
if (ext === '') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs.isfile(it)) {
|
|
||||||
let name = it.slice(PUBLIC_DIR.length + 1)
|
|
||||||
console.log(' 复制 %s ...', name)
|
|
||||||
fs.cp(it, join(dist, name))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('\n页面处理完成, 耗时 %ss\n', (Date.now() - timeStart) / 1000)
|
console.log('\n页面处理完成, 耗时 %ss\n', (Date.now() - timeStart) / 1000)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "fite",
|
"name": "fite",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.7.5",
|
"version": "0.8.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"fite": "index.js"
|
"fite": "index.js"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue