2
我有一个非常基本的Node.js + Express应用程序,使用React进行一些服务器和客户端渲染。当Express应用程序返回一个React呈现组件作为其响应的一部分时,它会返回给客户端,但未应用CSS。然后它快速闪烁到CSS呈现页面。我有点难以理解发生了什么,只是想要立即呈现CSS ...我有点新使用webpack &反应,所以任何帮助/解释将不胜感激。Webpack和SASS问题(React应用程序)
index.jade
html
head
title="Sample app"
meta(charset='utf-8')
meta(http-equiv='X-UA-Compatible', content='IE=edge')
meta(name='viewport', content='width=device-width, initial-scale=1')
body
#app!= content
script(src='http://localhost:8080/public/index.js')
App.js
if (process.env.BROWSER) require("../styles/App.scss");
import React from 'react';
export default class App extends React.Component {
render() {
return (
<div>
<p>Hello, world!</p>
</div>
)
}
}
server.js(片段)
...
app.get('/*', function (req, res) {
let content = React.renderToString(<App />);
res.render('index', { content: content });
});
...
工作就像一个魅力!谢谢你的背景! – thunderousNinja