Skip to content

Commit

Permalink
调整项目为服务端渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
tiankaiyuan committed May 26, 2018
1 parent 5196a67 commit 0d57e10
Show file tree
Hide file tree
Showing 34 changed files with 7,884 additions and 3,467 deletions.
20 changes: 19 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,23 @@
"es2015",
"stage-0",
"react"
]
],
"env": {
"node": {
"plugins": [
// 以下插件需要注意格式问题
[
"babel-plugin-transform-require-ignore",
{
"extensions": [
".less",
".css"
]
}
],
"dynamic-import-node"
]

}
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ pages/public
.DS_STORE
dist
dataBase
log
logs
pm2logs
apiServer/log
server/log

29 changes: 26 additions & 3 deletions appServer.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
const script = process.argv.includes('production') ? [] : [
{
script: './webpackStart.js',
cwd: './', //执行目录
name: 'webpack',
error_file: './pm2logs/webpackErrors.log',
out_file: './pm2logs/webpackOuts.log',
env: {
NODE_ENV: 'development',
BABEL_ENV: 'browser',
},
env_production: {
NODE_ENV: 'production',
BABEL_ENV: 'browser',
},
instance: 1,
autorestart: false,
watch: ['./webpackStart.js', './webpack.config.babel.js'], //默认监视执行目录(./),指定路径不能使用yml文件类型
}
]
module.exports = {
apps: [
{
script: './server/index.js',
cwd: './server/',
name: 'newApp',
error_file: '../pm2logs/newAppErrors.log',
out_file: '../pm2logs/newAppOuts.log',
env: {
NODE_ENV: 'development',
BABEL_ENV: 'node',
Expand All @@ -14,8 +36,9 @@ module.exports = {
},
instance: 1,
exec_mode: 'cluster',
watch: ['./','../logger','../shared'], //默认监视执行目录(./),指定路径不能使用yml文件类型
ignore_watch: ['log','dist']
}
watch: ['./', '../logger', '../shared'], //默认监视执行目录(./),指定路径不能使用yml文件类型
ignore_watch: ['log', 'dist']
},
...script
]
};
19 changes: 0 additions & 19 deletions client/index.html

This file was deleted.

7 changes: 4 additions & 3 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
* Created by tiankaiyuan on 2018/2/27.
*/
import React from 'react'
import {render} from 'react-dom'
import {hydrate} from 'react-dom'
import {Provider} from 'react-redux'
import {BrowserRouter} from 'react-router-dom'
import createStore from '../shared/store'
import Root from '../shared/containers/Root'
const store = createStore();
render(
const preStore = window.__INITIAL_STATE__ || {};
const store = createStore(preStore);
hydrate(
<Provider store={store}>
<BrowserRouter>
<Root/>
Expand Down
41 changes: 41 additions & 0 deletions logger/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Created by tiankaiyuan on 2018/3/12.
*/
const getAppenders = () => {
if (process.env.NODE_ENV !== 'production') {
return ['log', 'out']
} else {
return ['log']
}
};
let config = {
pm2: true, //设置说明log4js 是在pm2下使用,否则日志无效
appenders: {
out: {
type: 'stdout'
},
log: {
type: "file",
filename: "./log/log.log",
maxLogSize: 1048576,
backups: 3
}
},
categories: { // 通过配置这个属性进行分类,getLogger 未命中目标时,使用默认,appenders是同时触发的
default: {
appenders: getAppenders(),
level: "info"
},
apiServer: {
appenders: getAppenders(),
level: 'info'
},
appServer: {
appenders: getAppenders(),
level: 'info'
}
}
};


module.exports= config
19 changes: 19 additions & 0 deletions logger/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Created by tiankaiyuan on 2018/3/8.
*/
const log4 = require('log4js');
const config = require('./config');
// logger.trace('Entering cheese testing');
// logger.debug('Got cheese.');
// logger.info('Cheese is Gouda.');
// logger.warn('Cheese is quite smelly.');
// logger.error('Cheese is too ripe!');
// logger.fatal('Cheese was breeding ground for listeria.');
module.exports = (name) => {
log4.configure(config);
const logger = log4.getLogger(name);
if (process.env.NODE_ENV !== 'production') {
logger.level = 'debug';
}
return logger;
}
Loading

0 comments on commit 0d57e10

Please sign in to comment.