From b08b5c91726ebdb9855316c13c8d54844d4d6d3c Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 10 May 2023 13:22:02 +0000 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E6=A8=A1=E5=BC=8F=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0--no-clean=E9=85=8D=E7=BD=AE;=20=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E8=B0=83=E6=95=B4public=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E7=9A=84=E6=9D=83=E9=87=8D=E4=B8=BA=E6=9C=80=E4=BD=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierrc.yaml | 10 ++++++++++ index.js | 9 +++++---- lib/dev.js | 4 ++-- lib/prod.js | 40 +++++++++++++++++++--------------------- package.json | 2 +- 5 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 .prettierrc.yaml diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 0000000..b007fb1 --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,10 @@ +jsxBracketSameLine: true +jsxSingleQuote: true +semi: false +singleQuote: true +printWidth: 80 +useTabs: false +tabWidth: 2 +trailingComma: none +bracketSpacing: true +arrowParens: avoid \ No newline at end of file diff --git a/index.js b/index.js index 46cbd26..948622d 100755 --- a/index.js +++ b/index.js @@ -21,6 +21,8 @@ const PROTOCOL = IS_WINDOWS ? 'file://' : '' const NODE_VERSION = +process.versions.node.split('.').slice(0, 2).join('.') let args = process.argv.slice(2) +let mode = args.shift() || 'prod' +let clean = args.shift() !== '--no-clean' if (NODE_VERSION < 16.6) { console.log(red('Error: 你当前的环境不满足 Vue-live 构建工具的要求')) @@ -33,7 +35,7 @@ if (NODE_VERSION < 16.6) { process.exit() } -switch (args[0]) { +switch (mode) { case 'dev': import(PROTOCOL + CONFIG_FILE) .then(function (conf) { @@ -48,10 +50,9 @@ switch (args[0]) { import(PROTOCOL + CONFIG_FILE) .then(function (conf) { let dist = conf.buildDir || 'dist' - if (fs.isdir(dist)) { - fs.rm(dist, true) + if (clean && fs.isdir(dist)) { + fs.mkdir(dist) } - fs.mkdir(dist) compile(WORK_SPACE, dist, conf.default) }) .catch(err => { diff --git a/lib/dev.js b/lib/dev.js index 806101c..8b3f418 100644 --- a/lib/dev.js +++ b/lib/dev.js @@ -1,11 +1,11 @@ import http from 'http' import https from 'https' import fs from 'iofs' -import { join, resolve, dirname } from 'path' +import { join, dirname } from 'path' import { parse } from 'url' import socket from './ws.js' import chokidar from 'chokidar' -import { red, cyan, blue } from 'kolorist' +import { red } from 'kolorist' import { friendlyErrors } from './utils.js' diff --git a/lib/prod.js b/lib/prod.js index 62eba4f..b07d7fc 100644 --- a/lib/prod.js +++ b/lib/prod.js @@ -1,10 +1,8 @@ import fs from 'iofs' -import { join, resolve, dirname, parse } from 'path' +import { join, dirname, parse } from 'path' import Es from 'esbuild' import { compileScss, parseJs, compileVue, parseHtml } from './compile-vue.js' -const noc = Buffer.from('') - export default function compile(root = '', dist = '', conf = {}) { // 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) { let page = conf.pages[currentPage] let dir = dirname(page.entry) @@ -140,23 +156,5 @@ export default function compile(root = '', dist = '', conf = {}) { 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) } diff --git a/package.json b/package.json index 6dc91c4..7d5c853 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fite", "type": "module", - "version": "0.7.5", + "version": "0.8.0", "bin": { "fite": "index.js" },