1. const publicHtml = './public/index.html';
    2. const path = require('path');
    3. const webpack = require('webpack');
    4. const HtmlWepbackPlguin = require('html-webpack-plugin');
    5. const {CleanWebpackPlugin} = require('clean-webpack-plugin');
    6. const configA = {
    7. target:'web',
    8. entry:{
    9. a:'./src/test/a.js',
    10. b:'./src/test/b.js'
    11. },
    12. output:{
    13. filename:'[name].js',
    14. path:path.resolve(__dirname,'testDist')
    15. },
    16. devServer:{
    17. host:'127.0.0.1',
    18. port:'5555',
    19. contentBase:publicHtml
    20. },
    21. plugins:[
    22. // new CleanWebpackPlugin(),
    23. new HtmlWepbackPlguin({
    24. filename:'index.html',
    25. temlate:publicHtml,
    26. inject:true
    27. }),
    28. new webpack.DefinePlugin({
    29. env:JSON.stringify(process.env)
    30. })
    31. ],
    32. // optimization: {
    33. // runtimeChunk: 'single',
    34. // splitChunks: {
    35. // chunks: 'all',
    36. // maxInitialRequests: Infinity,
    37. // minSize: 0,
    38. // cacheGroups: {
    39. // vendor: {
    40. // test: /[\\/]node_modules[\\/]/,
    41. // name(module) {
    42. // // 获取第三方包名
    43. // const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
    44. // // npm 软件包名称是 URL 安全的,但是某些服务器不喜欢@符号
    45. // return `npm.${packageName.replace('@', '')}`;
    46. // },
    47. // },
    48. // },
    49. // },
    50. // },
    51. watch: true,
    52. // 自定义监视模式
    53. watchOptions: {
    54. // 排除监听
    55. ignored: /node_modules/,
    56. // 监听到变化发生后,延迟 300ms(默认) 再去执行动作,
    57. // 防止文件更新太快导致重新编译频率太高
    58. aggregateTimeout: 300,
    59. // 判断文件是否发生变化是通过不停的去询问系统指定文件有没有变化实现的
    60. // 默认 1000ms 询问一次
    61. poll: 1000
    62. }
    63. }
    64. const configB = {
    65. target:'node',
    66. entry:{
    67. a:'./src/test/a.js',
    68. b:'./src/test/b.js'
    69. },
    70. output:{
    71. filename:'[name].node.js',
    72. path:path.resolve(__dirname,'testDist')
    73. }
    74. }
    75. module.exports = [configA,configB]