webpack.base.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. var path = require('path')
  2. var webpack = require('webpack')
  3. const { VueLoaderPlugin } = require('vue-loader')
  4. const ESLintPlugin = require('eslint-webpack-plugin');
  5. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  6. module.exports = {
  7. module: {
  8. rules: [
  9. {
  10. test: /\.vue$/,
  11. loader: 'vue-loader',
  12. },
  13. {
  14. test: /\.js$/,
  15. loader: 'babel-loader',
  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',
  39. parser: {
  40. dataUrlCondition: {
  41. maxSize: 10240
  42. }
  43. },
  44. generator: {
  45. filename: './asset-image/[name][ext][query]'
  46. }
  47. },
  48. {
  49. test: /\.(eot|woff|woff2|ttf)$/,
  50. type:"asset/resource",
  51. generator:{
  52. filename:"./asset-font/[name].[hash:6][ext]"
  53. }
  54. },
  55. {
  56. test: /\.md$/,
  57. use: [
  58. {
  59. loader: "html-loader",
  60. },
  61. {
  62. loader: "markdown-loader",
  63. options: {
  64. // Pass options to marked
  65. // See https://marked.js.org/using_advanced#options
  66. },
  67. },
  68. ],
  69. },
  70. ]
  71. },
  72. resolve: {
  73. alias: {
  74. // 'vue$': 'vue/dist/vue.esm.js',
  75. '@static': path.resolve('static'),
  76. },
  77. extensions: ['*', '.js', '.vue', '.json']
  78. },
  79. performance: {
  80. hints: false
  81. },
  82. externals: {
  83. jQuery: 'window.$',
  84. jquery: 'window.$',
  85. bootstrap: 'bootstrap',
  86. BootstrapDialog: 'BootstrapDialog',
  87. d3: 'd3',
  88. echarts: 'echarts',
  89. moment: 'moment',
  90. },
  91. plugins: [
  92. new VueLoaderPlugin(),
  93. new ESLintPlugin({
  94. extensions: ['js', 'vue'],
  95. // 自动修复。
  96. // 自从eslint推出--fix命令后,如果觉得eslint格式化规则已经够用的话,其实也可以不用prettier了。
  97. fix: true,
  98. }),
  99. ]
  100. }