一、安装 package
webapck
webpack
webpack-cli
webpack-dev-server
webpack-merge
clean-webpack-plugin
javascript
babel-loader
@babel/core
@babel/preset-env
@babel/preset-react
css/sass/less
css-loader
style-loader
sass-loader
less-loader
postcss-loader
mini-css-extract-plugin
css-minimizer-webpack-plugin
html-inline-css-webpack-plugin
autoprefixer
cssnano
javascript
html-webpack-plugin
file
file-loader
url-loader
raw-loader
react
react
react-dom
typescript
typescript
ts-loader
others
glob
lib-flexible
二、webpack 配置
配置 webpack 的时候,一般写两份配置文件,一份开发环境,一份生产环境
package.json
{
"script": {
"build": "webpack",
"dev": "webpack dev --config ./webpack.dev.config.js",
"prod": "webpack --config ./webpack.prod.config.js"
}
}
webpack.config.js
const path = require('path')
module.exports = {
entry: {
main: './src/index.js'
},
output: {
filename: '[name].bundle.js'
},
mode: 'production',
}
「@浪里淘沙的小法师」