webpack.config.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //webpack全局配置
  2. const path = require('path');
  3. module.exports = function(env, argv) {
  4. // env是在package中运行的命令是配置
  5. env = env || {};
  6. return {
  7. entry: './src/main.js', //入口文件
  8. module: {
  9. rules: [
  10. // 处理css
  11. {
  12. test: /\.css$/i,
  13. use: ['vue-style-loader', 'css-loader']
  14. },
  15. // 处理vue
  16. {
  17. test: /\.vue$/i,
  18. use: 'vue-loader'
  19. },
  20. // 处理less
  21. {
  22. test: /\.less$/i,
  23. use: ['vue-style-loader', 'css-loader', 'less-loader']
  24. },
  25. // 小图片转为base64
  26. {
  27. test: /\.(png|jpg|gif)$/i,
  28. use: [{
  29. loader: 'url-loader',
  30. options: {
  31. limit: 10000
  32. }
  33. }]
  34. },
  35. // 处理es6
  36. {
  37. test: /\.(js)$/i,
  38. exclude: /node_modules/,
  39. use: {
  40. loader: 'babel-loader',
  41. options: {
  42. presets: ['@babel/preset-env']
  43. }
  44. }
  45. },
  46. // 多媒体文件
  47. {
  48. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  49. loader: 'url-loader',
  50. options: {
  51. limit: 10000,
  52. }
  53. },
  54. // 处理字体
  55. {
  56. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  57. loader: 'url-loader',
  58. options: {
  59. limit: 10000,
  60. }
  61. },
  62. //处理文件
  63. {
  64. test: /\.svg$/,
  65. use: 'file-loader'
  66. }
  67. ]
  68. },
  69. resolve: {
  70. extensions: ['.js', '.vue', '.json'],
  71. alias: {
  72. 'vue': 'vue/dist/vue.esm',
  73. '@': path.resolve(__dirname, 'src')
  74. }
  75. },
  76. ...(env.development ? require('./config/webpack.development') : require('./config/webpack.production'))
  77. }
  78. }