webpack.common.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* eslint-disable @typescript-eslint/no-var-requires */
  2. /* eslint-disable no-undef */
  3. /* 动态打包(dynamically bundle)
  4. 所有依赖项(创建所谓的依赖图(dependency graph)) */
  5. const path = require("path");
  6. const ProgressBarPlugin = require('progress-bar-webpack-plugin');
  7. const HtmlWebpackPlugin = require("html-webpack-plugin");
  8. const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
  9. const plugins = [
  10. //编译进度条
  11. new ProgressBarPlugin(),
  12. new MonacoWebpackPlugin({
  13. 'vs/nls': { availableLanguages: { '*': 'zh-cn' } },
  14. languages: ['sql', 'javascript']
  15. }),
  16. new HtmlWebpackPlugin({
  17. title: "运营数据中心",
  18. filename: "transfer.html",
  19. stylefile: path.resolve(__dirname, "../src/assets/css/common.css"),
  20. template: path.resolve(__dirname, "../public/index.html"),
  21. meta: {
  22. charset: "utf-8",
  23. },
  24. rootEl: "<div id='app'></div>",
  25. favicon: path.resolve(__dirname,"../public/favicon.ico"),
  26. globalApi: path.resolve(__dirname,"../public/baseUrlConfig.js"),
  27. publicPath: './'
  28. }),
  29. new HtmlWebpackPlugin({
  30. filename: "index.html",
  31. template: path.resolve(__dirname, "../public/transfer.html"),
  32. inject: false
  33. }),
  34. ];
  35. const name_ = 'data-operation-screen/'
  36. module.exports = {
  37. entry: [path.resolve(__dirname, "../src/index.js")],
  38. output: {
  39. filename: 'static/js/[name].[hash].js',
  40. chunkFilename: `static/js/[name].[chunkhash:8].js`,
  41. // filename: '[name].js',
  42. // chunkFilename: `[name].[chunkhash:8].js`,
  43. path: path.join(__dirname, '../dist'),
  44. },
  45. plugins,
  46. resolve: {
  47. alias: {
  48. "@assets": path.resolve(__dirname, "../src/assets/"),
  49. "@mock": path.resolve(__dirname, "../src/mock/"),
  50. "@pages": path.resolve(__dirname, "../src/pages/"),
  51. "@store": path.resolve(__dirname, "../src/store/"),
  52. "@components": path.resolve(__dirname, "../src/components/"),
  53. "@router": path.resolve(__dirname, "../src/router/"),
  54. "@apis": path.resolve(__dirname, "../src/apis/"),
  55. "@utils": path.resolve(__dirname, "../src/utils/"),
  56. "@config": path.resolve(__dirname, '../src/config'),
  57. "@themes": path.join(__dirname, '../src/themes'),
  58. "@widget": path.join(__dirname, '../src/widget'),
  59. },
  60. modules: [path.join(__dirname, 'src'), 'node_modules'],
  61. extensions: [".js", ".jsx", '.less', '.css']
  62. },
  63. module: {
  64. rules: /* 使用规则 */[
  65. // images
  66. {
  67. test: /* 匹配文件 */ /\.jpg|\.jpeg|\.png|\.gif|\.svg|\.ico/,
  68. include: [path.resolve(__dirname, "../src"), path.resolve(__dirname, "../public")],
  69. use: /* 使用loader */[{
  70. loader: "url-loader",
  71. options: /* 加载器相关的配置项 */ {
  72. name: 'static/[name].[ext]',
  73. limit: /* <=limit的图片转换成base64 */ 10000,
  74. mimetype: "image/jpg|image|gif/png|image/ico",
  75. fallback: 'file-loader',
  76. publicPath: '../../' //采用根路径
  77. },
  78. },
  79. ],
  80. },
  81. {
  82. test: /* 匹配文件 */ /\.gif/,
  83. include: [path.resolve(__dirname, "../node_modules")],
  84. use: /* 使用loader */[{
  85. loader: "url-loader",
  86. options: /* 加载器相关的配置项 */ {
  87. name: 'static/[name].[ext]',
  88. limit: /* <=limit的图片转换成base64 */ 10000,
  89. mimetype: "gif",
  90. fallback: 'file-loader',
  91. publicPath: '../../' //采用根路径
  92. },
  93. },
  94. ],
  95. },
  96. {
  97. test: /* 匹配文件 */ /\.svg/,
  98. include: [path.resolve(__dirname, "../src")],
  99. use: /* 使用loader */[{
  100. loader: "file-loader",
  101. options: /* 加载器相关的配置项 */ {
  102. name: 'static/[name].[ext]',
  103. publicPath: '../../' //采用根路径
  104. },
  105. },
  106. ],
  107. },
  108. {
  109. test: /\.(woff|woff2|ttf|eot)$/,
  110. // loader: 'file-loader?name=[name].[hash].[ext]'
  111. use: [{
  112. loader: 'file-loader',
  113. options: {
  114. name: 'static/[name].[ext]',
  115. publicPath: '../../'
  116. },
  117. }],
  118. },
  119. { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)$/,
  120. // use: 'file-loader' ,
  121. use: [{
  122. loader: 'file-loader',
  123. options: {
  124. name: name_+'static/[name].[ext]',
  125. publicPath: '../../'
  126. },
  127. }],
  128. },
  129. // babel
  130. {
  131. test: /\.jsx?$/,
  132. exclude: /(node_modules|bower_components)/,
  133. use: {
  134. loader: "babel-loader",
  135. options: {
  136. presets: ["@babel/preset-env", "@babel/preset-react"],
  137. plugins: ["@babel/plugin-transform-runtime"],
  138. },
  139. },
  140. },
  141. ],
  142. }
  143. };