webpack.common.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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: name_+'static/[name].[ext]',
  73. limit: /* <=limit的图片转换成base64 */ 8196,
  74. mimetype: "image/jpg|image|gif/png|image/ico",
  75. fallback: 'file-loader',
  76. publicPath: '../../' //采用根路径
  77. },
  78. },
  79. ],
  80. },
  81. {
  82. test: /* 匹配文件 */ /\.svg/,
  83. include: [path.resolve(__dirname, "../src")],
  84. use: /* 使用loader */[{
  85. loader: "file-loader",
  86. options: /* 加载器相关的配置项 */ {
  87. name: name_+'static/[name].[ext]',
  88. publicPath: '../../' //采用根路径
  89. },
  90. },
  91. ],
  92. },
  93. {
  94. test: /\.(woff|woff2|ttf|eot)$/,
  95. // loader: 'file-loader?name=[name].[hash].[ext]'
  96. use: [{
  97. loader: 'file-loader',
  98. options: {
  99. name: name_+'static/[name].[ext]',
  100. publicPath: '../../'
  101. },
  102. }],
  103. },
  104. { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)$/,
  105. // use: 'file-loader' ,
  106. use: [{
  107. loader: 'file-loader',
  108. options: {
  109. name: name_+'static/[name].[ext]',
  110. publicPath: '../../'
  111. },
  112. }],
  113. },
  114. // babel
  115. {
  116. test: /\.jsx?$/,
  117. exclude: /(node_modules|bower_components)/,
  118. use: {
  119. loader: "babel-loader",
  120. options: {
  121. presets: ["@babel/preset-env", "@babel/preset-react"],
  122. plugins: ["@babel/plugin-transform-runtime"],
  123. },
  124. },
  125. },
  126. ],
  127. }
  128. };