修复脑残windows

pull/1/head
yutent 2023-02-21 18:34:48 +08:00
parent cc348dccc4
commit b740b76867
4 changed files with 27 additions and 17 deletions

View File

@ -7,7 +7,7 @@
*/
import fs from 'iofs'
import { join } from 'path'
import { join, normalize } from 'path'
import createServer from './lib/dev.js'
import compile from './lib/prod.js'
@ -15,7 +15,7 @@ import compile from './lib/prod.js'
const WORK_SPACE = process.cwd()
const IS_WINDOWS = process.platform === 'win32'
const CONFIG_FILE = join(WORK_SPACE, 'vue.live.js')
const CONFIG_FILE = normalize(join(WORK_SPACE, 'vue.live.js'))
const PROTOCOL = IS_WINDOWS ? 'file://' : ''
let args = process.argv.slice(2)

View File

@ -8,7 +8,7 @@ import fs from 'iofs'
import scss from '@bytedo/sass'
import { createHash } from 'crypto'
import Es from 'esbuild'
import { resolve, join } from 'path'
import { join } from 'path'
import {
JS_EXP,
@ -23,6 +23,11 @@ const OPTIONS = {
indentWidth: 2
}
// 修正路径合并 避免在windows下被转义
function urlJoin(...args) {
return join(...args).replace(/\\/g, '/')
}
function md5(str = '') {
let sum = createHash('md5')
sum.update(str, 'utf8')
@ -89,7 +94,7 @@ export function parseJs(
/import ([\w\W]*?) from (["'])(.*?)\2/g,
function (m, alias, q, name) {
if (name.startsWith('@/')) {
name = name.replace('@/', join(DEPLOY_PATH, '/assets/js/'))
name = name.replace('@/', urlJoin(DEPLOY_PATH, '/assets/js/'))
}
if (!imports[name]) {
@ -98,14 +103,14 @@ export function parseJs(
if (IS_MPA) {
name = `${currentPage}/` + name
}
name = join(DEPLOY_PATH, '/assets/js/', name)
name = urlJoin(DEPLOY_PATH, '/assets/js/', name)
}
} else if (
name.startsWith('/') &&
!name.startsWith('//') &&
!name.startsWith(join(DEPLOY_PATH, '/assets/js/'))
!name.startsWith(urlJoin(DEPLOY_PATH, '/assets/js/'))
) {
name = name.replace(/^\//, join(DEPLOY_PATH, '/assets/js/'))
name = name.replace(/^\//, urlJoin(DEPLOY_PATH, '/assets/js/'))
}
if (!name.endsWith('.js') && !name.endsWith('.vue')) {
@ -143,11 +148,11 @@ export function parseJs(
// 修正那反人类的windows路径
return `import ${tmp} from '${name}' assert { type: 'css' }\n${tmp}.path = '${name.replace(
/\\/g,
'\\\\'
'/'
)}'`
} else {
if (name.startsWith('@/')) {
name = name.replace('@/', join(DEPLOY_PATH, '/assets/js/'))
name = name.replace('@/', urlJoin(DEPLOY_PATH, '/assets/js/'))
}
//
if (!imports[name]) {
@ -156,14 +161,14 @@ export function parseJs(
if (IS_MPA) {
name = `${currentPage}/` + name
}
name = join(DEPLOY_PATH, '/assets/js/', name)
name = urlJoin(DEPLOY_PATH, '/assets/js/', name)
}
} else if (
name.startsWith('/') &&
!name.startsWith('//') &&
!name.startsWith(join(DEPLOY_PATH, '/assets/js/'))
!name.startsWith(urlJoin(DEPLOY_PATH, '/assets/js/'))
) {
name = name.replace(/^\//, join(DEPLOY_PATH, '/assets/js/'))
name = name.replace(/^\//, urlJoin(DEPLOY_PATH, '/assets/js/'))
}
if (!name.endsWith('.js') && !name.endsWith('.vue')) {
@ -232,7 +237,7 @@ stylesheet.path = '${file
.slice(
options.IS_MPA ? options.pagesDir.length : options.SOURCE_DIR.length
)
.replace(/\\/g, '\\\\')}'
.replace(/\\/g, '/')}'
stylesheet.replaceSync(\`${CACHE[file].css}\`)
document.adoptedStyleSheets.push(stylesheet)
`

View File

@ -30,7 +30,7 @@ export default async function createServer(root = '', conf = {}) {
if (!SERVER_OPTIONS.key || !SERVER_OPTIONS.cert) {
console.error('证书错误: https 证书不能为空!!!\n')
process.exit(1)
process.exit()
}
}
@ -138,6 +138,8 @@ export default async function createServer(root = '', conf = {}) {
DEPLOY_PATH
})
// console.log(entry);
code = parseHtml(html, { page, imports: conf.imports, entry })
}
@ -290,7 +292,10 @@ export default async function createServer(root = '', conf = {}) {
case 'scss':
{
let content = fs.cat(filePath).toString()
ws.send({ action: 'render', data: { path: file, content } })
ws.send({
action: 'render',
data: { path: file.replace(/\\/g, '/'), content }
})
}
break
@ -310,7 +315,7 @@ export default async function createServer(root = '', conf = {}) {
} else {
ws.send({
action: 'render',
data: { path: file, content: tmp.css }
data: { path: file.replace(/\\/g, '/'), content: tmp.css }
})
}
}

View File

@ -1,7 +1,7 @@
{
"name": "@bytedo/vue-live",
"type": "module",
"version": "0.2.1",
"version": "0.2.2",
"bin": {
"vue-live": "index.js"
},