为什么即使webpack没有抛出任何错误,React组件也不会呈现?

时间:2017-03-11 18:44:22

标签: javascript node.js reactjs express webpack

应用-client.js

var React = require('react');
var APP = require('./components/APP');
React.render(<APP />, document.getElementById('react-container'));

App.js (组件)     var React = require(&#39; react&#39;);

var APP = React.createClass({
  render() {
    return (<h1>Hello World form React</h1>);
  }
});

module.exports = APP;

webpack.config.js 我遇到了webpack的问题,但解决了添加了预设的问题。它现在运行良好。

module.exports = {
  entry: "./app-client.js", 
  output: {
    filename: "public/bundle.js"
},
module: {
    loaders: [
        {
            exclude: /(node_modules|app-server.js)/,
            loader: "babel-loader",
            query: {
                presets: [
                    'es2015',
                    'react'
                ]
            }
        }
    ]
  }
};

的index.html:

<div id="react-container" class="container">
    <h1>Live Polling</h1>
</div>  
<script type="text/javascript" src="bundle.js"></script>

文件夹结构

app-client.js
app-server.js
components
  - app.js
public
  - bundle.js
  - index.html
  - style.css
webpack.config.js
package.json

我运行webpack,然后启动服务器,但div内部的内容&#34; react-container&#34;不要被组件(app.js)覆盖。

1 个答案:

答案 0 :(得分:1)

React self功能已从render模块移至React,请尝试以下操作:

ReactDOM