webpack.base.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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',
  34. 'postcss-loader'] : ['style-loader', 'css-loader', 'postcss-loader'],
  35. // ‌‌PostCSS**的核心作用‌是转换CSS和处理CSS。它通过插件机制来处理CSS文件,支持各种转换任务,如自动添加浏览器前缀、压缩代码、使用未来CSS语法等。‌
  36. },
  37. // 处理链条(从右到左)
  38. /**
  39. * 1.postcss-loader:执行 PostCSS 插件(Tailwind + Autoprefixer)
  40. * 2.css-loader:解析 CSS 中的 import 和 url()
  41. * 3.style-loader(开发环境):将 CSS 注入到 <style> 标签
  42. * 4.MiniCssExtractPlugin.loader(生产环境):提取 CSS 到单独文件
  43. */
  44. {
  45. test: /\.(png|jpg|gif|svg)$/,
  46. loader: 'file-loader',
  47. options: {
  48. name: './client-wms-board.image/[name].[ext]?[hash]',
  49. },
  50. },
  51. {
  52. test: /\.(eot|woff|woff2|ttf)$/,
  53. loader: 'file-loader',
  54. options: {
  55. name: './font/[name].[ext]?[hash]',
  56. },
  57. },
  58. ],
  59. },
  60. resolve: {
  61. alias: {
  62. // 'vue$': 'vue/dist/vue.esm.js',
  63. '@static': path.resolve('static'),
  64. },
  65. extensions: ['*', '.js', '.vue', '.json'],
  66. },
  67. performance: {
  68. hints: false,
  69. },
  70. externals: {
  71. bootstrap: 'bootstrap',
  72. BootstrapDialog: 'BootstrapDialog',
  73. d3: 'd3',
  74. echarts: 'echarts',
  75. moment: 'moment',
  76. },
  77. plugins: [
  78. new VueLoaderPlugin(),
  79. new ESLintPlugin({
  80. extensions: ['js', 'vue'],
  81. // 自动修复。
  82. // 自从eslint推出--fix命令后,如果觉得eslint格式化规则已经够用的话,其实也可以不用prettier了。
  83. fix: true,
  84. }),
  85. ],
  86. };