微调代码解析
parent
5497bd18fa
commit
8769ed24ba
|
@ -89,8 +89,8 @@ export function parseJs(
|
||||||
isBuild
|
isBuild
|
||||||
) {
|
) {
|
||||||
let fixedStyle = '\n\n'
|
let fixedStyle = '\n\n'
|
||||||
let ASSETS_JS = '/$ASSETS_JS/'
|
let ASSETS_JS = '/@/'
|
||||||
let ASSETS_CSS = '/$ASSETS_CSS/'
|
let ASSETS_CSS = '/@/'
|
||||||
|
|
||||||
if (isBuild) {
|
if (isBuild) {
|
||||||
ASSETS_JS = '/assets/js/'
|
ASSETS_JS = '/assets/js/'
|
||||||
|
|
47
lib/dev.js
47
lib/dev.js
|
@ -7,6 +7,8 @@ import socket from './ws.js'
|
||||||
import chokidar from 'chokidar'
|
import chokidar from 'chokidar'
|
||||||
import { red, cyan, blue } from 'kolorist'
|
import { red, cyan, blue } from 'kolorist'
|
||||||
|
|
||||||
|
import { friendlyErrors } from './utils.js'
|
||||||
|
|
||||||
import { compileScss, parseJs, compileVue, parseHtml } from './compile-vue.js'
|
import { compileScss, parseJs, compileVue, parseHtml } from './compile-vue.js'
|
||||||
|
|
||||||
import MIME_TYPES from './mime-tpyes.js'
|
import MIME_TYPES from './mime-tpyes.js'
|
||||||
|
@ -143,7 +145,7 @@ export default async function createServer(root = '', conf = {}) {
|
||||||
|
|
||||||
case 'vue':
|
case 'vue':
|
||||||
{
|
{
|
||||||
let rpath = pathname.replace(/\$ASSETS_JS\//, '')
|
let rpath = pathname.replace(/@\//, '')
|
||||||
let file
|
let file
|
||||||
|
|
||||||
if (IS_MPA) {
|
if (IS_MPA) {
|
||||||
|
@ -157,18 +159,7 @@ export default async function createServer(root = '', conf = {}) {
|
||||||
file = join(SOURCE_DIR, rpath)
|
file = join(SOURCE_DIR, rpath)
|
||||||
}
|
}
|
||||||
if (!fs.isfile(file)) {
|
if (!fs.isfile(file)) {
|
||||||
console.log(
|
friendlyErrors(pathname, ext)
|
||||||
'%s %s \n @try to read %s',
|
|
||||||
cyan(rpath),
|
|
||||||
red(`not found!!!`),
|
|
||||||
file
|
|
||||||
)
|
|
||||||
console.log(
|
|
||||||
red(
|
|
||||||
'请正确填写引入的文件路径, vue-live 不再自动补全【%s】\n'
|
|
||||||
),
|
|
||||||
blue('/index.vue')
|
|
||||||
)
|
|
||||||
res.writeHead(404, 'Not Found')
|
res.writeHead(404, 'Not Found')
|
||||||
res.end('')
|
res.end('')
|
||||||
return
|
return
|
||||||
|
@ -189,12 +180,18 @@ export default async function createServer(root = '', conf = {}) {
|
||||||
case 'scss':
|
case 'scss':
|
||||||
case 'css':
|
case 'css':
|
||||||
{
|
{
|
||||||
let file = join(
|
let file = join(SOURCE_DIR, pathname.replace(/@\//, ''))
|
||||||
SOURCE_DIR,
|
if (!fs.isfile(file)) {
|
||||||
pathname
|
file = join(PUBLIC_DIR, pathname.replace(/@\//, ''))
|
||||||
.replace(/\$ASSETS_CSS\//, '')
|
|
||||||
.replace(/\$ASSETS_JS\//, '')
|
if (!fs.isfile(file)) {
|
||||||
)
|
friendlyErrors(pathname, ext)
|
||||||
|
res.setHeader('content-type', MIME_TYPES.html)
|
||||||
|
res.writeHead(404, 'Not Found')
|
||||||
|
res.end('')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
code = compileScss(file)
|
code = compileScss(file)
|
||||||
res.setHeader('content-type', MIME_TYPES.css)
|
res.setHeader('content-type', MIME_TYPES.css)
|
||||||
}
|
}
|
||||||
|
@ -202,7 +199,7 @@ export default async function createServer(root = '', conf = {}) {
|
||||||
|
|
||||||
case 'js':
|
case 'js':
|
||||||
{
|
{
|
||||||
pathname = pathname.replace(/\$ASSETS_JS\//, '')
|
pathname = pathname.replace(/@\//, '')
|
||||||
let file
|
let file
|
||||||
if (IS_MPA) {
|
if (IS_MPA) {
|
||||||
if (pathname.startsWith(currentPage)) {
|
if (pathname.startsWith(currentPage)) {
|
||||||
|
@ -219,13 +216,7 @@ export default async function createServer(root = '', conf = {}) {
|
||||||
} else if (fs.isfile(join(PUBLIC_DIR, pathname))) {
|
} else if (fs.isfile(join(PUBLIC_DIR, pathname))) {
|
||||||
code = fs.cat(join(PUBLIC_DIR, pathname))
|
code = fs.cat(join(PUBLIC_DIR, pathname))
|
||||||
} else {
|
} else {
|
||||||
console.log(cyan(pathname), red(`not found!!!`))
|
friendlyErrors(pathname, ext)
|
||||||
console.log(
|
|
||||||
red(
|
|
||||||
'请正确填写引入的文件路径, vue-live 不再自动补全【%s】\n'
|
|
||||||
),
|
|
||||||
blue('/index.js')
|
|
||||||
)
|
|
||||||
res.writeHead(404, 'Not Found')
|
res.writeHead(404, 'Not Found')
|
||||||
res.end('')
|
res.end('')
|
||||||
return
|
return
|
||||||
|
@ -251,7 +242,7 @@ export default async function createServer(root = '', conf = {}) {
|
||||||
code = null
|
code = null
|
||||||
}
|
}
|
||||||
if (code === null) {
|
if (code === null) {
|
||||||
console.log(cyan(pathname), red(`not found!!!`))
|
friendlyErrors(pathname, ext)
|
||||||
res.writeHead(404, 'Not Found')
|
res.writeHead(404, 'Not Found')
|
||||||
res.end('')
|
res.end('')
|
||||||
return
|
return
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { red, cyan, blue } from 'kolorist'
|
||||||
|
|
||||||
|
export function friendlyErrors(pathname, ext = '') {
|
||||||
|
console.log(cyan(pathname), red(`not found!!!`))
|
||||||
|
console.log(
|
||||||
|
red('请正确填写引入的文件路径, fite 不再自动补全【%s】\n'),
|
||||||
|
blue(`/index.${ext}`)
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in New Issue