webpack.base.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. 'moment': 'moment',
  70. 'vue': 'Vue',
  71. 'vue-i18n': 'VueI18n',
  72. 'vue-router': 'VueRouter',
  73. 'vuex': 'Vuex',
  74. // 'gantt': 'gantt'
  75. },
  76. plugins: [
  77. new VueLoaderPlugin(),
  78. new ESLintPlugin({
  79. extensions: ['js', 'vue'],
  80. // 自动修复。
  81. // 自从eslint推出--fix命令后,如果觉得eslint格式化规则已经够用的话,其实也可以不用prettier了。
  82. fix: true,
  83. }),
  84. ]
  85. }