在package.json中:
{
"name": "myr",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "webpack -d --watch",
"build": "webpack -p",
"start": "webpack -d ; node ./bin/www"
},
"dependencies": {
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"body-parser": "~1.17.1",
"cookie-parser": "~1.4.3",
"debug": "~2.6.3",
"express": "~4.15.2",
"jade": "~1.11.0",
"morgan": "~1.8.1",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"serve-favicon": "~2.4.2"
},
"devDependencies": {
"babel-core": "^6.25.0",
"webpack": "^2.6.1"
}
}
在webpack.config.js中:
var webpack = require('webpack');
var path = require('path');
var BUILD_DIR = path.resolve(__dirname, '');
var APP_DIR = path.resolve(__dirname, 'app');
var config = {
entry: APP_DIR + '/index.jsx',
output: {
path: BUILD_DIR,
filename: 'bundle.js'
},
module : {
loaders : [
{
test : /\.jsx?/,
include : APP_DIR,
loader : 'babel-loader',
query: {
presets: ['es2015', 'react']
}
}
]
}
};
module.exports = config;
在index.jsx中:
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import AwesomeComponent from './AwesomeComponent.jsx';
class App extends Component {
render () {
return (
<div>
<p> Hello React!</p>
<AwesomeComponent />
</div>
);
}
}
ReactDOM.render(<App/>, document.getElementByID('app'));
我试图调查bundle.js
,但没有多大帮助。
我浏览了其他帖子,无法找到答案。
React存在于node_modules和package.json
中