Skip to content

Commit 029efbe

Browse files
committed
feat: update config
1 parent 309aa1b commit 029efbe

9 files changed

+48
-61
lines changed

.eslintrc.json

+14-14
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
"no-multiple-empty-lines": "off",
129129
"no-new-wrappers": "error",
130130
"no-lonely-if": "off",
131-
"no-param-reassign":"off",
131+
"no-param-reassign": "off",
132132
"no-shadow": [
133133
"off",
134134
{
@@ -164,7 +164,7 @@
164164
"spaced-comment": ["error", "always", { "markers": ["/"] }],
165165
"use-isnan": "error",
166166
"valid-typeof": "off",
167-
"prefer-destructuring":"off",
167+
"prefer-destructuring": "off",
168168
"react/jsx-no-target-blank": [
169169
"error",
170170
{
@@ -237,18 +237,18 @@
237237
"ecmaVersion": 12,
238238
"sourceType": "module"
239239
}
240-
},
241-
{
242-
// enable the rule specifically for TypeScript files
243-
"files": ["*.js", "*.ts"],
244-
"rules": {
245-
"@typescript-eslint/explicit-module-boundary-types": [
246-
"error",
247-
{
248-
"allowArgumentsExplicitlyTypedAsAny":true
249-
}
250-
]
251-
}
252240
}
241+
// {
242+
// // enable the rule specifically for TypeScript files
243+
// "files": ["*.js", "*.ts"],
244+
// "rules": {
245+
// "@typescript-eslint/explicit-module-boundary-types": [
246+
// "error",
247+
// {
248+
// "allowArgumentsExplicitlyTypedAsAny":true
249+
// }
250+
// ]
251+
// }
252+
// }
253253
]
254254
}

README.md

+6-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# react ssr 开发体验初步升级
1+
# noov.js
22

33
服务运行
44

@@ -7,28 +7,10 @@ npm i
77
npm run dev
88
```
99

10-
## 升级内容
11-
12-
- 前端代码的实时构建
13-
- 服务端所需代码的实时编译
14-
- http 服务的自动重启
15-
16-
## 缺陷
17-
18-
页面的显示内容需要刷新一次才能看到。 后续继续优化,增加热更新。
19-
2010
## 待做
2111

22-
- 修复构建的 strat.js bug
23-
- server koa===>改造成 ts
24-
- build server 改造成 server
25-
- 支持 redux
26-
- server 端引入 ejs 进行渲染返回 ===> 参考 nuxt
27-
- css
28-
- 按需加载
29-
- 引用 umi 文档构建
30-
- 单元测试
31-
- 8080 所有路由 获取 index 文件然后返回
32-
- 项目还得支持 sourceMap 的引入
33-
34-
做成一个完整的项目
12+
- [ ] 文档补充
13+
- [ ] 单元测试
14+
- [ ] 看看 nuxt 如何做 ssr
15+
- [ ] start.js 优化
16+
- [ ] ts 类型完善

build/client/dev-server.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ const express = require('express')
33
const webpack = require('webpack')
44
const devMiddleware = require('webpack-dev-middleware')
55
const hotMiddleware = require('webpack-hot-middleware')
6-
const proConfig = require('../../config/pro-config')
76
const webpackConfig = require('./webpack.dev.conf')
7+
const proConfig = require('../../config/pro-config')
88
const config = require('../../config')
99
const port = config.dev.port
10-
10+
const constant = require('../../config/constant')
1111
const getPort = require('get-port')
12-
12+
const chalk = require('chalk')
1313
const main = function () {
1414
getPort({
1515
port: getPort.makeRange(port, port + 100)
@@ -53,7 +53,12 @@ const main = function () {
5353

5454
console.log('> Starting dev server...')
5555
webpackDevMiddleware.waitUntilValid(() => {
56-
console.log(`> Listening at ${config.dev.host}:${proConfig.nodeServerPort} \n`)
56+
console.log(`> client Listening at ${config.dev.host}:${newPort} \n`)
57+
console.log(
58+
chalk.green(
59+
`> server Listening at ${config.dev.host}:${proConfig.nodeServerPort} \n`
60+
)
61+
)
5762
})
5863
app.listen(newPort)
5964
})

build/client/webpack.base.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = {
7171
},
7272

7373
plugins: [
74-
new FriendlyErrorsWebpackPlugin(),
74+
// new FriendlyErrorsWebpackPlugin(),
7575
new ForkTsCheckerWebpackPlugin(),
7676
new ESLintPlugin({
7777
fix: true

build/client/webpack.dev.conf.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const webpack = require('webpack')
2-
const {merge} = require('webpack-merge')
2+
const { merge } = require('webpack-merge')
33
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
44
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
55

@@ -16,7 +16,7 @@ module.exports = merge(baseWebpackConfig, {
1616
main: ['webpack-hot-middleware/client?path=__hmr', './src/client/main/index.tsx']
1717
},
1818
module: {
19-
rules:[
19+
rules: [
2020
{
2121
test: /\.(le|c)ss$/,
2222
use: [
@@ -30,13 +30,13 @@ module.exports = merge(baseWebpackConfig, {
3030
'postcss-loader',
3131
'less-loader'
3232
]
33-
},
33+
}
3434
]
3535
},
3636
devtool: 'cheap-source-map',
3737
plugins: [
3838
new FriendlyErrorsWebpackPlugin(),
39-
new webpack.HotModuleReplacementPlugin(),
39+
new webpack.HotModuleReplacementPlugin(),
4040
new BundleAnalyzerPlugin.BundleAnalyzerPlugin({
4141
openAnalyzer: false,
4242
analyzerPort: 'auto'

build/start.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ const localHostIp = getIp()
1919

2020
log(chalk.green('servers starting....'))
2121

22-
// 服务端代码监控和构建进程
23-
const svrCodeWatchProcess = spawn('npm', ['run', 'server-dev:build'], {
24-
shell: process.platform === 'win32'
25-
})
26-
2722
// 前端代码构建 服务进程
2823
const feCodeWatchProcess = spawn('npm', ['run', 'client:dev', localHostIp], {
2924
stdio: 'inherit',
3025
shell: process.platform === 'win32'
3126
})
3227

28+
// 服务端代码监控和构建进程
29+
let svrCodeWatchProcess = spawn('npm', ['run', 'server-dev:build'], {
30+
shell: process.platform === 'win32'
31+
})
32+
// 监听服务端代码构建服务的对外输出 stdout 事件
33+
svrCodeWatchProcess.stdout.on('data', print)
34+
3335
// node 服务进程
3436
let nodeServerProcess = null
3537
// 启动 node 服务
@@ -54,9 +56,6 @@ function print(data) {
5456
}
5557
}
5658

57-
// 监听服务端代码构建服务的对外输出 stdout 事件
58-
svrCodeWatchProcess.stdout.on('data', print)
59-
6059
// 杀掉子进程
6160
const killChild = () => {
6261
svrCodeWatchProcess && svrCodeWatchProcess.kill()

config/constant.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// 用于开发环境的构建过程中的常量
22

33
module.exports = {
4-
SVRCODECOMPLETED:'编译完成...'// 服务端代码编译完成
5-
}
4+
SVRCODECOMPLETED: '编译完成...', // 服务端代码编译完成
5+
CLIENTCOMPILEDONE: '客户端编译完成...'
6+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "now",
2+
"name": "noov",
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",

src/server/app/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ app.use(koaStatic('./dist/static'))
3232
app.use(ssrMiddleware)
3333

3434
// 启动服务
35-
app.listen(port)
36-
37-
console.log('server is start .', `http://localhost:${port}`)
35+
app.listen(port, () => {
36+
console.log('server is start .', `http://localhost:${port}`)
37+
})

0 commit comments

Comments
 (0)