webpack.common.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. module.exports = {
  36. entry: [path.resolve(__dirname, "../src/index.js")],
  37. output: {
  38. filename: 'static/js/[name].[hash].js',
  39. chunkFilename: `static/js/[name].[chunkhash:8].js`,
  40. // filename: '[name].js',
  41. // chunkFilename: `[name].[chunkhash:8].js`,
  42. path: path.join(__dirname, '../dist'),
  43. },
  44. plugins,
  45. resolve: {
  46. alias: {
  47. "@assets": path.resolve(__dirname, "../src/assets/"),
  48. "@mock": path.resolve(__dirname, "../src/mock/"),
  49. "@pages": path.resolve(__dirname, "../src/pages/"),
  50. "@store": path.resolve(__dirname, "../src/store/"),
  51. "@components": path.resolve(__dirname, "../src/components/"),
  52. "@router": path.resolve(__dirname, "../src/router/"),
  53. "@apis": path.resolve(__dirname, "../src/apis/"),
  54. "@utils": path.resolve(__dirname, "../src/utils/"),
  55. "@config": path.resolve(__dirname, '../src/config'),
  56. "@themes": path.join(__dirname, '../src/themes'),
  57. "@widget": path.join(__dirname, '../src/widget'),
  58. },
  59. modules: [path.join(__dirname, 'src'), 'node_modules'],
  60. extensions: [".js", ".jsx", '.less', '.css']
  61. },
  62. module: {
  63. rules: /* 使用规则 */[
  64. // images
  65. {
  66. test: /* 匹配文件 */ /\.jpg|\.jpeg|\.png|\.svg|\.ico/,
  67. include: [path.resolve(__dirname, "../src"), path.resolve(__dirname, "../public")],
  68. use: /* 使用loader */[{
  69. loader: "url-loader",
  70. options: /* 加载器相关的配置项 */ {
  71. name: 'static/[name].[ext]',
  72. limit: /* <=limit的图片转换成base64 */ 8196,
  73. mimetype: "image/jpg|image/png|image/ico",
  74. fallback: 'file-loader',
  75. publicPath: '../../' //采用根路径
  76. },
  77. },
  78. ],
  79. },
  80. {
  81. test: /* 匹配文件 */ /\.svg/,
  82. include: [path.resolve(__dirname, "../src")],
  83. use: /* 使用loader */[{
  84. loader: "file-loader",
  85. options: /* 加载器相关的配置项 */ {
  86. name: 'static/[name].[ext]',
  87. publicPath: '../../' //采用根路径
  88. },
  89. },
  90. ],
  91. },
  92. {
  93. test: /\.(woff|woff2|ttf|eot)$/,
  94. // loader: 'file-loader?name=[name].[hash].[ext]'
  95. use: [{
  96. loader: 'file-loader',
  97. options: {
  98. name: 'static/css/[name].[hash].[ext]',
  99. publicPath: '../../'
  100. },
  101. }],
  102. },
  103. // babel
  104. {
  105. test: /\.jsx?$/,
  106. exclude: /(node_modules|bower_components)/,
  107. use: {
  108. loader: "babel-loader",
  109. options: {
  110. presets: ["@babel/preset-env", "@babel/preset-react"],
  111. plugins: ["@babel/plugin-transform-runtime"],
  112. },
  113. },
  114. },
  115. ],
  116. }
  117. };