1 查看上一篇文章,并按照步骤来
2 自动打包(有需要再添加)
webpack.config.js 添加 watch:true
3 npm安装react相关
--save-dev react
react-dom
--save babel-preset-react
设置 webpack.config.js ==> query: {presets: ['es2015','react']}
4 demo文件
入口:a.js
import React from "react";
import ReactDOM from "react-dom";
import Hello from "./hello";
ReactDOM.render(
<Hello />,
document.querySelector('#app')
);
引用:hello.js
import React from "react";
class Hello extends React.Component{
render() {
return (
<div>
Hello, World!
</div>
)
}
}
export default Hello;
5 编译,运行
webpack编译下,webpack-dev-server服务器,打开 http://127.0.0.1:8080/dist/
ok!