【发布时间】:2018-10-16 01:57:27
【问题描述】:
我正在开发一个应用程序,它将 create-react-app 与快速服务器(使用服务器渲染)连接起来。我指的是this tutorial。要从服务器渲染文件,代码是
bootstrap.js
require('ignore-styles');
require('babel-register')({
ignore:[/(node-modules)/],
presets:['es2015','react-app']
});
require('./index');
index.js
import express from 'express';
// we'll talk about this in a minute:
import serverRenderer from './middleware/renderer';
const PORT = 3000;
const path = require('path');
// initialize the application and create the routes
const app = express();
const router = express.Router();
// root (/) should always serve our server rendered page
router.use('^/$', serverRenderer);
// other static resources should just be served as they are
router.use(express.static(
path.resolve(__dirname, '..', 'build'),
{ maxAge: '30d' },
));
// tell the app to use the above rules
app.use(router);
// start the app
app.listen(PORT, (error) => {
if (error) {
return console.log('something bad happened', error);
}
console.log("listening on " + PORT + "...");
});
运行命令时
node bootstrap.js
我收到错误提示
错误:使用
babel-preset-react-app需要您指定NODE_ENV或BABEL_ENV环境变量。有效值为“开发”、“测试”和“生产”。
【问题讨论】:
标签: reactjs express redux babeljs create-react-app