webpack.base.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. var path = require('path')
  2. const { VueLoaderPlugin } = require('vue-loader')
  3. const ESLintPlugin = require('eslint-webpack-plugin');
  4. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  5. module.exports = {
  6. module: {
  7. rules: [
  8. {
  9. test: /\.vue$/,
  10. loader: 'vue-loader',
  11. },
  12. {
  13. test: /\.js$/,
  14. loader: 'babel-loader',
  15. // include: [
  16. // path.resolve(__dirname, './node_modules/pc-component-v3/dist/pc-component-v3.js'),
  17. // ],
  18. // exclude: file => (
  19. // /node_modules/.test(file) &&
  20. // !/\.vue\.js/.test(file)
  21. // ),
  22. },
  23. {
  24. test: /\.css$/,
  25. use: (process.env.NODE_ENV === 'production') ? [
  26. {
  27. loader: MiniCssExtractPlugin.loader,
  28. options: {
  29. publicPath: '../'
  30. }
  31. },
  32. 'css-loader'] : ['style-loader', 'css-loader']
  33. },
  34. {
  35. // webpack5 通过资源模块来处理图片
  36. test: /\.(png|jpg|gif|svg)$/,
  37. type: 'asset/resource',
  38. parser: {
  39. dataUrlCondition: {
  40. maxSize: 10240,
  41. },
  42. },
  43. generator: {
  44. filename: './client-trace-v3-image/[name][ext][query]',
  45. },
  46. },
  47. {
  48. test: /\.(eot|woff|woff2|ttf)$/,
  49. type: 'asset/resource',
  50. generator: {
  51. filename: './client-trace-v3-font/[name].[ext]?[hash]',
  52. },
  53. },
  54. ]
  55. },
  56. resolve: {
  57. alias: {
  58. '@static': path.resolve('static'),
  59. },
  60. extensions: ['*', '.js', '.vue', '.json']
  61. },
  62. performance: {
  63. hints: false
  64. },
  65. externals: {
  66. 'jquery': "window.jquery",
  67. 'bootstrap': 'bootstrap',
  68. 'BootstrapDialog': 'BootstrapDialog',
  69. 'vue': 'Vue',
  70. 'vue-i18n': 'VueI18n',
  71. 'vue-router': 'VueRouter',
  72. 'vuex': 'Vuex',
  73. // 'gantt': 'gantt'
  74. },
  75. plugins: [
  76. new VueLoaderPlugin(),
  77. new ESLintPlugin({
  78. extensions: ['js', 'vue'],
  79. // 自动修复。
  80. // 自从eslint推出--fix命令后,如果觉得eslint格式化规则已经够用的话,其实也可以不用prettier了。
  81. fix: true,
  82. }),
  83. ]
  84. }