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. exclude: /node_modules/,
  16. // include: [
  17. // path.resolve(__dirname, './node_modules/pc-component-v3/dist/pc-component-v3.js'),
  18. // ],
  19. // exclude: file => (
  20. // /node_modules/.test(file) &&
  21. // !/\.vue\.js/.test(file)
  22. // ),
  23. },
  24. {
  25. test: /\.css$/,
  26. use: (process.env.NODE_ENV === 'production') ? [
  27. {
  28. loader: MiniCssExtractPlugin.loader,
  29. options: {
  30. publicPath: '../'
  31. }
  32. },
  33. 'css-loader'] : ['style-loader', 'css-loader']
  34. },
  35. {
  36. // webpack5 通过资源模块来处理图片
  37. test: /\.(png|jpg|gif|svg)$/,
  38. type: 'asset/resource',
  39. parser: {
  40. dataUrlCondition: {
  41. maxSize: 10240,
  42. },
  43. },
  44. generator: {
  45. filename: './client-trace-v5-image/[name][ext][query]',
  46. },
  47. },
  48. {
  49. test: /\.(eot|woff|woff2|ttf)$/,
  50. type: 'asset/resource',
  51. generator: {
  52. filename: './client-trace-v5-font/[name].[ext]?[hash]',
  53. },
  54. },
  55. ]
  56. },
  57. resolve: {
  58. alias: {
  59. '@static': path.resolve('static'),
  60. },
  61. extensions: ['*', '.js', '.vue', '.json']
  62. },
  63. performance: {
  64. hints: false
  65. },
  66. externals: {
  67. 'jquery': "window.jquery",
  68. 'bootstrap': 'bootstrap',
  69. 'BootstrapDialog': 'BootstrapDialog',
  70. 'vue': 'Vue',
  71. 'vue-i18n': 'VueI18n',
  72. 'vue-router': 'VueRouter',
  73. 'vuex': 'Vuex',
  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. }