You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. const path = require("path");
  2. const webpack = require('webpack');
  3. const TerserPlugin = require("terser-webpack-plugin");
  4. const HappyPack = require('happypack');
  5. const os = require('os');
  6. const happyThreadPool = HappyPack.ThreadPool({
  7. size: os.cpus().length
  8. });
  9. const common = require("./common");
  10. const pathVars = require("./pathVars");
  11. const pageVars = require("./pageVars");
  12. //---------------------------------- output -----------------------------------//
  13. const entryConfig = {};
  14. let charts = pageVars.getCharts();
  15. charts.forEach((chartItem) => {
  16. entryConfig[chartItem["chunkName"]] = chartItem["entryJs"];
  17. });
  18. console.log("entryConfig", entryConfig);
  19. //---------------------------------- output -----------------------------------//
  20. let outputConfig = {
  21. path: pathVars.chartsDistPath,
  22. publicPath: "./", // 表示资源的发布地址,当配置过该属性后,打包文件中所有通过相对路径引用的资源都会被配置的路径所替换(如:css中背景图的路径)
  23. filename: "[name].js",
  24. library: "[name]",
  25. libraryExport: 'default',
  26. umdNamedDefine: true,
  27. // es umd
  28. libraryTarget: "umd",
  29. assetModuleFilename: 'chartImages/[name]_[hash][ext][query]'
  30. };
  31. //---------------------------------- plugin -----------------------------------//
  32. let pluginConfig = [
  33. new HappyPack({
  34. id: 'babel',
  35. loaders: ["babel-loader"],
  36. threadPool: happyThreadPool
  37. })
  38. ];
  39. module.exports = {
  40. mode: 'production',
  41. entry: entryConfig,
  42. output: outputConfig,
  43. resolve: common.resolve,
  44. module: {
  45. rules: [{
  46. test: /\.(css|less)$/,
  47. include: [pathVars.srcPath],
  48. exclude: [pathVars.nodeModulesPath],
  49. use: [{
  50. options: {
  51. /* 解决css背景图路径问题 由于图片目录已经定好了,因此这里可以用固定的相对路径*/
  52. publicPath: '../'
  53. },
  54. },
  55. //"css-loader?modules&localIdentName=[name]__[local]-[hash:base64:5]",
  56. "css-loader",
  57. "less-loader"
  58. ],
  59. },
  60. {
  61. test: /\.js$/,
  62. exclude: pathVars.nodeModulesPath,
  63. include: pathVars.srcPath,
  64. use: ['babel-loader']
  65. //use: ["happypack/loader?id=babel"]
  66. },
  67. {
  68. test: /\.(png|jpg|gif|woff|svg|eot|ttf|woff2)$/,
  69. type: 'asset/resource',
  70. parser: {
  71. dataUrlCondition: {
  72. maxSize: 10 * 1024
  73. }
  74. }
  75. },
  76. {
  77. test: /\.(glsl|vs|fs|vert|frag)$/,
  78. exclude: [pathVars.nodeModulesPath, pathVars.dllPath],
  79. use: ["raw-loader", "glslify-loader"]
  80. }
  81. ]
  82. },
  83. plugins: pluginConfig,
  84. optimization: {
  85. minimize: true,
  86. minimizer: [
  87. new TerserPlugin()
  88. ]
  89. }
  90. };