1. cnpm i webpack-dev-server -S
    1. "name": "workpack",
    2. "version": "1.0.0",
    3. "description": "",
    4. "private": true,
    5. "main": "index.js",
    6. "scripts": {
    7. "build": "webpack --config webpack.config.js",
    8. "serve": "webpack serve --open"
    9. },
    const webpack = require("webpack")
    const path = require("path")
    const HtmlWebpackPlugin = require("html-webpack-plugin")
    const {CleanWebpackPlugin} = require("clean-webpack-plugin")
    const config ={
        entry:path.resolve(__dirname,'src/main.js'), // 入口文件
        output:{
            path:path.resolve(__dirname,'dist'),     // 出口文件
            filename:'[hash]-[name]-bundle.js'
        },
        module:{
            rules:[
                {
                    test:/\.css$/i,
                    use:['style-loader','css-loader']
                }
            ]
        },
        plugins:[
            new HtmlWebpackPlugin({
                title:'workpack'
            }),
            new CleanWebpackPlugin()
        ],
        devServer:{
            contentBase: './dist',
        },
        mode:'development'    // 模式
    }
    module.exports = config;
    
    npm run serve