我在用eggjs服务器端渲染时(我只想获得渲染好的HTML),总是报解析jsx代码或者import失败,然后我在代码最前面加上了 require(‘babel-polyfill’); require(‘babel-register’)({ presets: [ ‘env’, ‘react’, ‘stage-0’ ], }); 也没有效果,请问我该如何是好,在生产环境下,又该怎么做呢?下面是我的代码: ‘use strict’; require(‘babel-polyfill’); require(‘babel-register’)({ presets: [ ‘env’, ‘react’, ‘stage-0’ ], }); const Controller = require(‘egg’).Controller; const React = require(‘react’); const ReactDOMServer = require(‘react-dom/server’); const App = require(’…/…/components’); class HomeController extends Controller { async index() { const html = ReactDOMServer.renderToString(<App />); this.ctx.body = ‘hi, egg’; } }
module.exports = HomeController;
在生产环境,又该怎么做呢?