New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

live-dev-server

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

live-dev-server - npm Package Compare versions

Comparing version

to
0.4.1

27

index.js

@@ -15,2 +15,3 @@ const http = require('http')

const projectRoot = process.cwd()
const defaultWorkspace = path.join(projectRoot,`./src`)

@@ -31,3 +32,3 @@ const opts = {

before: null,
workspace: `${projectRoot}/src`,
workspace: defaultWorkspace,
root: projectRoot,

@@ -37,8 +38,12 @@ send: {},

}
console.log(projectRoot)
// 读取配置文件
try {
let config = require(`${projectRoot}/lds.config.js`)
let config = require(path.join(projectRoot,`./lds.config.js`))
let { workspace, ...restConfig } = config
let extra = {
workspace: workspace ? path.join(projectRoot, workspace) : defaultWorkspace
}
// TODO deep merge
opts = Object.assign(opts, config)
Object.assign(opts, restConfig, extra)
} catch (error) {

@@ -126,4 +131,5 @@ console.log('没有lds.config.js配置文件')

}
let needInject = reqPath == '' || reqPath.indexOf('.html') > -1
// 如果是/demo/src/的时候,会指向到demo/src/index.html,这种情况需要注入inject片段
let maybeNeedInject = reqPath == '' || reqPath.indexOf('.html') > -1 || originalUrl.pathname.substr(-1) === '/'
let sendOpts = Object.assign(

@@ -136,5 +142,10 @@ {

if (needInject) {
if (maybeNeedInject) {
handleInject = function (stream) {
let len = INJECT_SCRIPT.length
// 判断是否是html, 决定是否注入
let ctstr = res.getHeader('content-type')
if (ctstr.indexOf('html') < 0) return
if (customInjectScript.length) {

@@ -173,3 +184,3 @@ len += customInjectScript.length

// pipe
needInject && sendStream.on('stream', handleInject)
maybeNeedInject && sendStream.on('stream', handleInject)
sendStream.pipe(res)

@@ -176,0 +187,0 @@ })

{
"name": "live-dev-server",
"version": "0.4.0",
"version": "0.4.1",
"description": "develop env, watch files change, mock data",

@@ -5,0 +5,0 @@ "main": "index.js",