pull/1/head
yutent 2022-09-28 18:56:47 +08:00
parent cd9f780212
commit c2f7afedcb
2 changed files with 178 additions and 147 deletions

30
index.js Executable file
View File

@ -0,0 +1,30 @@
#!/bin/env node
/**
* {}
* @author yutent<yutent.io@gmail.com>
* @date 2022/09/28 15:12:45
*/
import { join } from 'path'
import { createServer } from './lib/index.js'
const WORK_SPACE = process.env.INIT_CWD
let args = process.argv.slice(2)
switch (args[0]) {
case 'dev':
import(join(WORK_SPACE, 'vue.live.js'))
.then(function (conf) {
// console.log(conf)
createServer(WORK_SPACE, conf.default)
})
.catch(err => {
console.log('Import Error:', err)
})
break
case 'build':
break
}

View File

@ -8,7 +8,7 @@ import http from 'http'
import fs from 'iofs' import fs from 'iofs'
import { join, resolve } from 'path' import { join, resolve } from 'path'
import { parse } from 'url' import { parse } from 'url'
import conf from './live.config.js.js' // import conf from './live.config.js'
import { compileScss, parseJs, compileVue } from './compile-vue.js' import { compileScss, parseJs, compileVue } from './compile-vue.js'
@ -16,10 +16,10 @@ import MIME_TYPES from './mime-tpyes.js'
import { COMMON_HEADERS } from './constants.js' import { COMMON_HEADERS } from './constants.js'
const decode = decodeURIComponent const decode = decodeURIComponent
const root = resolve('./src/')
/* ------------------------------- */ /* ------------------------------- */
export function createServer(root = '', conf = {}) {
let pagesDir = resolve(conf.pages) let pagesDir = resolve(conf.pages)
let pages = fs.ls(pagesDir).map(it => { let pages = fs.ls(pagesDir).map(it => {
let tmp = it.slice(pagesDir.length + 1) + '.html' let tmp = it.slice(pagesDir.length + 1) + '.html'
@ -195,5 +195,6 @@ http
createServer() createServer()
}) })
.on('listening', _ => { .on('listening', _ => {
// console.log('启动成功, 请访问', 'http://127.0.0.1:' + conf.port) console.log('启动成功, 请访问', 'http://127.0.0.1:' + conf.port)
}) })
}