const {resolve} = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    entry: './src/index.js',
    output:{
        filename: 'built.js',
        path: resolve(__dirname,'build')
    },
    module:{
        rules:[
            {
                test: /\.css$/,
                use: ['style-loader','css-loader']
            },
            //打包其他资源 除了html js css
            {
                exclude:/\.(css|js|html|less)$/,
                loader:'file-loader',
                options:{
                    esModule: false,
                    name: '[hash:10].[ext]'
                },
                type: 'javascript/auto'
            }
        ]
    },
    plugins:[
        new HtmlWebpackPlugin({
            template: './src/index.html'
        })
    ],
    mode: 'development',

    //开发服务器 devServer
    //只会再内存中编译，不会有任何输出
    //启动指令 npx webpack serve
    devServer:{
        contentBase: resolve(__dirname, 'build'),
        // 启动gzip压缩
        compress:true,
        port:3000,
        // 自动打开浏览器
        open:true
    }
    
}