fileRules.js 854 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const { assetsPath, resolve } = require('./../utils');
  2. const { threadLoader, cacheLoader } = require('./loaders');
  3. function getUrlloader(assetsPrefix) {
  4. return {
  5. loader: 'url-loader',
  6. options: {
  7. limit: 10000,
  8. name: assetsPath(`${assetsPrefix}/[name].[contenthash:7].[ext]`),
  9. },
  10. };
  11. }
  12. module.exports = [
  13. {
  14. test: /\.(png|jpe?g|svg|gif|webp)$/,
  15. // 相当于 url-loader 的自动根据文件大小的配置能力
  16. type: 'asset',
  17. generator: {
  18. filename: 'assets/images/[name].[contenthash:8][ext]',
  19. },
  20. parser: {
  21. dataUrlCondition: {
  22. maxSize: 8 * 1024, // 8kb
  23. },
  24. },
  25. },
  26. {
  27. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  28. use: [getUrlloader('fonts')],
  29. },
  30. {
  31. test: /\.svg$/,
  32. use: [cacheLoader, threadLoader(), '@svgr/webpack'],
  33. include: [resolve('src')],
  34. },
  35. ];