搭建原生react-webpack整合项目
- 初始化项目依赖文件 package.json
npm init -y
- 安装webpack相关的依赖 webpack/webpack-cli/webpack-dev-server
npm i -D webpack webpack-cli webpack-dev-server
- 安装react相关的依赖 react/react-dom
npm i -S react react-dom
- 配置webpack.config.js文件
- 安装html-webpack-plugin/copy-webpack-plugin
npm i -D copy-webpack-plugin html-webpack-plugin
- 配置脚本启动命令
- “dev” : “webpack-dev-server”
- 安装jsx和ECMA最新语法解析插件
npm i -D babel-loader @babel/preset-env @babel/preset-react @babel/plugin-proposal-class-properties
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
module.export = {
entry: './src/index.js',
devServer: {
stats: "errors-only",
contentBase: path.resolve(__dirname,"./dist")
},
output: {
path: path.resolve(__dirname,'./dist'),
filename: 'main.js'
},
module: {
rules: [
{
test: /\.j(s|sx)$/,
use:"babel-loader",
exclude: path.resolve(__dirname,"./node_modules")
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname,'./public/index.html')
}),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname,'./public'),
to: path.resolve(__dirname,'./dist')
}
])
]
}
module.export = {
presets: ["@babel/preset-env", "@babel/preset-react"],
plugins: ['@babel/plugin-proposal-class-properties']
}
plugins: ['@babel/plugin-proposal-class-properties']
}