loader.prod.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* eslint-disable import/no-extraneous-dependencies */
  2. const fs = require('fs');
  3. const path = require('path');
  4. const paths = require('./paths');
  5. const loaders = require('./loader.dev');
  6. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  7. const lessToJs = require('less-vars-to-js');
  8. const themeVariables = lessToJs(fs.readFileSync(path.join(paths.appSrc, 'styles/ant-default.less'), 'utf8'));
  9. const iconPath = path.relative('./~/antd/lib/style/*', './src/styles/iconfont/antd-font/iconfont');
  10. themeVariables['@icon-url'] = `'${iconPath}'`;
  11. // js & jsx loader
  12. const jsLoader = {
  13. test: /\.(js|jsx)$/,
  14. include: paths.appSrc,
  15. exclude: /node_modules/,
  16. loader: require.resolve('babel-loader'),
  17. };
  18. const cssLoaderRule = {
  19. test: /\.css$/,
  20. use: [
  21. MiniCssExtractPlugin.loader,
  22. loaders.cssLoaderConfig,
  23. loaders.postCssLoaderConfig,
  24. { loader: 'resolve-url-loader' },
  25. ],
  26. };
  27. const scssLoaderRule = {
  28. test: /\.(scss|sass)$/,
  29. use: [
  30. MiniCssExtractPlugin.loader,
  31. loaders.cssLoaderConfig,
  32. loaders.postCssLoaderConfig,
  33. { loader: 'resolve-url-loader' },
  34. loaders.sassLoaderConfig,
  35. ],
  36. };
  37. const lessLoaderRule = {
  38. test: /\.(less)$/,
  39. use: [
  40. MiniCssExtractPlugin.loader,
  41. loaders.cssLoaderConfig,
  42. loaders.postCssLoaderConfig,
  43. { loader: 'resolve-url-loader' },
  44. loaders.lessLoaderConfig,
  45. ],
  46. };
  47. module.exports = { ...loaders, scssLoaderRule, lessLoaderRule, cssLoaderRule, jsLoader };