欢迎大家访问我的博客 blog.ayla1688.cool
### react本地打包
在写完页面后, 执行 ```node /scripts/build.js``` 对项目进行打包, 完成后,项目文件就在build 文件夹中。
将build文件夹中的所有文件放在服务器的根目录上, 然后对web服务器进行配置, 配置参考
###[点击查看](https://router.vuejs.org/zh/guide/essentials/history-mode.html)
###nginx配置
```
location / {
try_files $uri $uri/ /index.html;
}
```
###apache配置
```
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
```
###node配置
```
const http = require('http')
const fs = require('fs')
const httpPort = 80
http.createServer((req, res) => {
fs.readFile('index.htm', 'utf-8', (err, content) => {
if (err) {
console.log('We cannot open "index.htm" file.')
}
res.writeHead(200, {
'Content-Type': 'text/html; charset=utf-8'
})
res.end(content)
})
}).listen(httpPort, () => {
console.log('Server listening on: http://localhost:%s', httpPort)
})
```