这些东东不难,只是工程结构和开发流程有些专业。
我不是专业写前端,但自己的代码中,VUE.JS,JQUERY之类的也用得不少,了解一下总是有好处的。
这本书,写得不错,概念,实操都一步一步的。
~~~~~~~~~~~~~~~
当然,webpack的版本是基于1x的,到2x要自己作一些语法转换。
~~~~~~~~~~~~~~~
看到一小半,将一个系统工程的文件呈现一下,便于总结记忆。
package.json
{
"name": "react",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack",
"dev": "webpack-dev-server --hot"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-react-hmre": "^1.1.1",
"eslint": "^4.11.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx": "0.0.2",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.5.1",
"html-webpack-plugin": "^2.30.1",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.4"
},
"dependencies": {
"react": "^16.1.1",
"react-dom": "^16.1.1"
}
}
webpack.config.js
var path = require("path");
var webpack = require("webpack");
var HtmlwebpackPlugin = require("html-webpack-plugin");
var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, "app");
var BUILD_PATH = path.resolve(ROOT_PATH, "build");
module.exports = {
entry: {
app: path.resolve(APP_PATH, "app.jsx")
},
output: {
path: BUILD_PATH,
filename: "bundle.js"
},
resolve: {
extensions: [".js", ".jsx"]
},
devtool: "eval-source-map",
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
progress: true
},
module: {
rules: [
{
test: /\.jsx?$/,
enforce: "pre",
loaders: ["eslint-loader"],
include: APP_PATH
},
{
test: /\.jsx?$/,
loaders: ["babel-loader"],
include: APP_PATH
}
]
},
plugins: [
new HtmlwebpackPlugin({
title: "My first react app"
})
]
}
.babelrc(在WINDOWS里,不可以直接建.开头的文件,最好用一些文本编辑器通过保存来产生)
{
"presets": ["es2015", "react"],
"env": {
"development": {
"presets": ["react-hmre"]
}
}
}
.eslintrc
{
"extends": "airbnb",
"rules": {
"comma-dangle": ["error", "never"],
"linebreak-style": ["error", "windows"]
},
"env": {
"browser": true
}
}
app.jsx
import React from 'react';
import ReactDOM from 'react-dom';
function App() {
return (
<div className="container">
<h1>Hello React World!</h1>
</div>
);
}
const app = document.createElement('div');
document.body.appendChild(app);
ReactDOM.render(<App />, app);
看出如下界面,就表示,基础环境搭好啦...:)
时间: 2024-09-13 18:49:01