const publicHtml = './public/index.html';const path = require('path');const webpack = require('webpack');const HtmlWepbackPlguin = require('html-webpack-plugin');const {CleanWebpackPlugin} = require('clean-webpack-plugin');const configA = { target:'web', entry:{ a:'./src/test/a.js', b:'./src/test/b.js' }, output:{ filename:'[name].js', path:path.resolve(__dirname,'testDist') }, devServer:{ host:'127.0.0.1', port:'5555', contentBase:publicHtml }, plugins:[ // new CleanWebpackPlugin(), new HtmlWepbackPlguin({ filename:'index.html', temlate:publicHtml, inject:true }), new webpack.DefinePlugin({ env:JSON.stringify(process.env) }) ], // optimization: { // runtimeChunk: 'single', // splitChunks: { // chunks: 'all', // maxInitialRequests: Infinity, // minSize: 0, // cacheGroups: { // vendor: { // test: /[\\/]node_modules[\\/]/, // name(module) { // // 获取第三方包名 // const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]; // // npm 软件包名称是 URL 安全的,但是某些服务器不喜欢@符号 // return `npm.${packageName.replace('@', '')}`; // }, // }, // }, // }, // }, watch: true, // 自定义监视模式 watchOptions: { // 排除监听 ignored: /node_modules/, // 监听到变化发生后,延迟 300ms(默认) 再去执行动作, // 防止文件更新太快导致重新编译频率太高 aggregateTimeout: 300, // 判断文件是否发生变化是通过不停的去询问系统指定文件有没有变化实现的 // 默认 1000ms 询问一次 poll: 1000 }}const configB = { target:'node', entry:{ a:'./src/test/a.js', b:'./src/test/b.js' }, output:{ filename:'[name].node.js', path:path.resolve(__dirname,'testDist') }}module.exports = [configA,configB]