![](/img/trans.png)
[英]React page is different when using "npm start" and "npm run deploy"
[英]Page not displaying on npm start using node, react
我正在嘗試使用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'));
./components/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. 對於渲染,您應該使用React 插入的ReactDOM
var React = require('react');
var ReactDOM = require('react-dom');
ReactDOM.render( <CommentBox />, document.getElementById('react'));
2. reactify已棄用:請改用babelify (確保已使用babel-preset-react配置Babel)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.