basis
// Webpack base configuration object
const HtmlWebpackPlugin = require('Html-webpack-plugin'); // Generate an HTML template
module.export = {
entry:'./src/main.js'.output: {filename:'build.js'
path:path.resolve(_dirname,'dist')},module: {rules:[
{
test:'.css$'.use: ['style-loader'.'css-loader']]}},plugins: [new HtmlWebpackPlugin({
template:'./index.html'}})]Copy the code
Commonly used loader
- Css-loader, style-loader // Process CSS
- MiniCssExtractPlugin. Loader / / CSS out of a separate file
- Url-loader // parse image resources:
- File-loader // Parse other file resources:
- Html-withimg-loader // Parse images in HTML:
- Postcss-loader // Handle CSS compatibility, usage and corresponding plug-ins to see webpack official website
- Babel-loader // handles JS compatibility and can only handle simple compatibility, not advanced syntax like Promise
The plugin is commonly used
const HtmlWebpackPlugin = require('Html-webpack-plugin'); // Generate an HTML template
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); / / CSS to pull away
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin'); / / compress CSS
Copy the code