Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. const withLess = require('@zeit/next-less')
  2. const withCSS = require('@zeit/next-css');
  3. const lessToJS = require('less-vars-to-js')
  4. const fs = require('fs')
  5. const path = require('path')
  6. const withPlugins = require('next-compose-plugins');
  7.  
  8. // Where your antd-custom.less file lives
  9. const themeVariables = lessToJS(
  10. fs.readFileSync(path.resolve(__dirname, './assets/antd-custom.less'), 'utf8')
  11. )
  12.  
  13. const nextConfig = {
  14. lessLoaderOptions: {
  15. javascriptEnabled: true,
  16. modifyVars: themeVariables, // make your antd custom effective
  17. },
  18. webpack: (config, { isServer }) => {
  19. if (isServer) {
  20. const antStyles = /antd\/.*?\/style.*?/
  21. const origExternals = [...config.externals]
  22. config.externals = [
  23. (context, request, callback) => {
  24. if (request.match(antStyles)) return callback()
  25. if (typeof origExternals[0] === 'function') {
  26. origExternals[0](context, request, callback)
  27. } else {
  28. callback()
  29. }
  30. },
  31. ...(typeof origExternals[0] === 'function' ? [] : origExternals),
  32. ]
  33.  
  34. config.module.rules.unshift({
  35. test: antStyles,
  36. use: 'null-loader',
  37. })
  38. }
  39. return config
  40. },
  41. };
  42.  
  43. module.exports = withPlugins(
  44. [
  45. [withCSS],
  46. [
  47. withLess,
  48. {
  49. cssModules: true,
  50. cssLoaderOptions: {
  51. localIdentName: '[path]___[local]___[hash:base64:5]',
  52. },
  53. },
  54. ],
  55. ],
  56. nextConfig,
  57. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement