页面没有显示在npm上开始使用节点,做出反应

时间:2016-07-02 10:34:59

标签: reactjs npm flux

我正在尝试使用NPM创建一个简单的页面并做出反应。

index.html文件:

<html lang="en">
  <head>
    <meta charset="utf-8">
    <title> Flux Comment Box </title>
  </head>
  <body>
    <section id="react"></section>
    <script src="js/bundle.js"></script>
  </body>
</html>

./ JS / app.js

var CommentBox = require('./components/CommentBox.react');
var React = require('react');
window.React = React;

React.render( <CommentBox />, document.getElementById('react'));

./组件/ CommentBox.react.js

var CommentStore = require('../stores/CommentStore');
var React = require('react');
var CommentBox = React.createClass ({
  render: function () {
    return (
      <div> HI </div>
    );
  },
});

module.exports(CommentBox);

当我执行“npm start”时(我的package.json应该没问题,我会在下面发布),它说

2870222 bytes written to js/bundle.js (2.44 seconds)

但index.html是一个没有错误或警告的空白页面。 怎么了?

供参考,这是我的package.json

{
"name": "Basic-comment-box",
"version": "0.0.1",
"description": "Basic flux project",
"main": "js/app.js",

"dependencies": {
  "classnames": "^2.1.3",
  "flux": "^2.0.0",
  "keymirror": "~0.1.0",
  "object-assign": "^1.0.0",
  "react": "^0.12.0"
},
"devDependencies": {
    "browserify": "^6.2.0",
    "envify": "^3.0.0",
    "jest-cli": "^0.4.3",
    "reactify": "^0.15.2",
    "uglify-js": "~2.4.15",
    "watchify": "^2.1.1"
},
"scripts": {
    "start": "watchify -o js/bundle.js -v -d js/app.js",
    "build": "browserify . -t [envify --NODE_ENV production] | uglifyjs -cm > js/bundle.min.js",
    "test": "jest"
},
"author": "Timothy Chu",
"license": "Apache 2",
"browserify": {
"transform": [
  "reactify",
  "envify"
]
},
"jest": {
"rootDir": "./js"
}
}

1 个答案:

答案 0 :(得分:0)

1. for render 你应该使用 ReactDOM insact of React

var React = require('react');
var ReactDOM = require('react-dom');

ReactDOM.render( <CommentBox />, document.getElementById('react'));

2. 重新设置已弃用:改为使用 babelify (确保您使用babel-preset-react配置了Babel)