Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

webpack.charts.dev.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. const path = require("path");
  2. const webpack = require('webpack');
  3. const HtmlWebpackPlugin = require("html-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 pages = pageVars.getChartsTest();
  15. pages.forEach((page) => {
  16. entryConfig[page["chunkName"]] = page["entryJs"];
  17. });
  18. //---------------------------------- output -----------------------------------//
  19. let outputConfig = {
  20. path: pathVars.devPath,
  21. // publicPath: "./", // 表示资源的发布地址,当配置过该属性后,打包文件中所有通过相对路径引用的资源都会被配置的路径所替换(如:css中背景图的路径)
  22. filename: "[name]/index.js",
  23. assetModuleFilename: 'chartImages/[name]_[hash][ext][query]'
  24. };
  25. //---------------------------------- plugin -----------------------------------//
  26. let pluginConfig = [
  27. new webpack.ProvidePlugin({
  28. 'THREE': require.resolve('three')
  29. }),
  30. new webpack.DllReferencePlugin({
  31. context: pathVars.rootPath,
  32. manifest: require(pathVars.dllPath + '/manifest.json')
  33. }),
  34. new HappyPack({
  35. id: 'babel',
  36. loaders: ["babel-loader"],
  37. threadPool: happyThreadPool
  38. })
  39. ];
  40. pages.forEach(function (page) {
  41. let htmlPlugin = new HtmlWebpackPlugin({
  42. title: 'chartTest',
  43. template: page["htmlPath"],
  44. filename: page["htmlName"],
  45. inject: 'body',
  46. chunks: [page["chunkName"]]
  47. });
  48. pluginConfig.push(htmlPlugin);
  49. });
  50. module.exports = {
  51. mode: 'development',
  52. entry: entryConfig,
  53. output: outputConfig,
  54. resolve: common.resolve,
  55. devServer: {
  56. compress: true,
  57. static: {
  58. directory: pathVars.devPath,
  59. publicPath: "/"
  60. },
  61. hot: true,
  62. host: 'localhost',
  63. port: 3000
  64. },
  65. module: {
  66. rules: [{
  67. test: /\.(css|less)$/,
  68. include: [pathVars.srcPath],
  69. exclude: [pathVars.nodeModulesPath],
  70. use: [{
  71. options: {
  72. /* 解决css背景图路径问题 由于图片目录已经定好了,因此这里可以用固定的相对路径*/
  73. publicPath: '../'
  74. },
  75. },
  76. //"css-loader?modules&localIdentName=[name]__[local]-[hash:base64:5]",
  77. "css-loader",
  78. "less-loader"
  79. ],
  80. },
  81. {
  82. test: /\.js$/,
  83. exclude: pathVars.nodeModulesPath,
  84. include: pathVars.srcPath,
  85. use: ['babel-loader']
  86. //use: ["happypack/loader?id=babel"]
  87. },
  88. {
  89. test: /\.(png|jpg|gif|woff|svg|eot|ttf|woff2)$/,
  90. type: 'asset/resource',
  91. parser: {
  92. dataUrlCondition: {
  93. maxSize: 10 * 1024
  94. }
  95. }
  96. },
  97. {
  98. test: /\.(glsl|vs|fs|vert|frag)$/,
  99. exclude: [pathVars.nodeModulesPath, pathVars.dllPath],
  100. use: ["raw-loader", "glslify-loader"]
  101. }
  102. ]
  103. },
  104. plugins: pluginConfig,
  105. optimization: {
  106. runtimeChunk: 'single',
  107. splitChunks: {
  108. chunks: "all",
  109. cacheGroups: {
  110. vendor: {
  111. test: /[\\/]node_modules[\\/]/,
  112. name: 'vendor',
  113. chunks: 'all'
  114. }
  115. }
  116. }
  117. }
  118. };