All Projects → SolidZORO → next-plugin-antd-less

SolidZORO / next-plugin-antd-less

Licence: MIT license
🎩 Use Antd (Less) with Next.js v12, Zero Dependency on other Next-Plugins.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to next-plugin-antd-less

next-plugin-antd
A @zeit/next-less patch with full support for Ant Design, Less and CSS modules
Stars: ✭ 27 (-92.01%)
Mutual labels:  less, css-modules, ant-design, next-plugin
umi-plugin-antd-theme
🎨 Best theme plugin
Stars: ✭ 77 (-77.22%)
Mutual labels:  antd, ant-design, antdpro
React Antd Multi Tabs Admin
ts+react+antd-多页签后台模板(纯净版,非 antd pro!)
Stars: ✭ 73 (-78.4%)
Mutual labels:  less, antd, ant-design
Ng Alain
NG-ZORRO admin panel front-end framework (surge mirror https://ng-alain-doc.surge.sh)
Stars: ✭ 4,287 (+1168.34%)
Mutual labels:  antd, ant-design, antd-design-pro
Ant Design Dark Theme
🌚 Dark theme variables of Ant Design
Stars: ✭ 431 (+27.51%)
Mutual labels:  less, antd, ant-design
Ant Design Aliyun Theme
⚙ Ant Design Theme for console.aliyun.com
Stars: ✭ 237 (-29.88%)
Mutual labels:  less, antd, ant-design
React Antd Todo
A simple todo list app built with React, Redux and Antd - Ant Design
Stars: ✭ 42 (-87.57%)
Mutual labels:  less, antd, ant-design
React Redux Antdesign Webpack Starter
react + redux + ant design + react-router 4 + webpack 4 starter
Stars: ✭ 44 (-86.98%)
Mutual labels:  less, antd, ant-design
React Admin
🎉 A magical react admin
Stars: ✭ 149 (-55.92%)
Mutual labels:  less, ant-design
React Native Css Modules
Style React Native components using CSS, PostCSS, Sass, Less or Stylus.
Stars: ✭ 207 (-38.76%)
Mutual labels:  less, css-modules
react-antd-formutil
Happy to use react-formutil in the project based on ant-design ^_^
Stars: ✭ 16 (-95.27%)
Mutual labels:  antd, ant-design
Antd Live Theme
Customize Ant Design specific colors dynamically on runtime
Stars: ✭ 116 (-65.68%)
Mutual labels:  less, antd
Rollup Plugin Styles
🎨 Universal Rollup plugin for styles: PostCSS, Sass, Less, Stylus and more.
Stars: ✭ 116 (-65.68%)
Mutual labels:  less, css-modules
nextjs-antd-custom
This project we created a simple project with Nextjs and use Ant Design for CSS components and also deploy that with Now.sh
Stars: ✭ 28 (-91.72%)
Mutual labels:  less, antd
ant-design-icons
Ant Design + Material Design Icon =
Stars: ✭ 21 (-93.79%)
Mutual labels:  antd, ant-design
elm-antd
The official Ant Design UI Kit for Elm
Stars: ✭ 56 (-83.43%)
Mutual labels:  antd, ant-design
Moo Css
模块化面向对象的css写法规范策略。适用于大中小型C端项目样式开发,旨在提高开发和维护效率。
Stars: ✭ 79 (-76.63%)
Mutual labels:  less, css-modules
antd-form-mate
📦 基于 ant design 的表单组件,配置化实现表单功能。
Stars: ✭ 14 (-95.86%)
Mutual labels:  antd, ant-design
tiny-qiniu-request
tiny-qiniu for rc-upload or antd upload component `customRequest` property
Stars: ✭ 13 (-96.15%)
Mutual labels:  antd, ant-design
picker
📅 All Date Pickers you need.
Stars: ✭ 185 (-45.27%)
Mutual labels:  antd, ant-design

Next.js + Antd (with Less)

version license size download

Use Antd (Less) w/ Next.js, Zero Dependency on other Next-Plugins.

Demo

Demo w/ Next.js v12 by mkn

Demo w/ CRA v5 by mkr

Yep! this plugin supports both Next.js and CRA since v1.0.

Features

  • Zero Dependency on other Next.js Plugins
  • Support Both Next.js & CRA Project
  • Support Hot-Update After modifying Antd less vars
  • Support Serverless Mode
  • Support Antd Pro

Compatibility

  • Next.js v11 / v12
  • CRA v4 / v5

Installation

yarn add next-plugin-antd-less
yarn add --dev babel-plugin-import

Usage

for Next.js

// next.config.js
const withAntdLess = require('next-plugin-antd-less');

module.exports = withAntdLess({
  modifyVars: { '@primary-color': '#04f' }, // optional
  lessVarsFilePath: './src/styles/variables.less', // optional 
  lessVarsFilePathAppendToEndOfContent: false, // optional
  // optional https://github.com/webpack-contrib/css-loader#object
  cssLoaderOptions: {
    // ... 
    mode: "local",
    localIdentName: __DEV__ ? "[local]--[hash:base64:4]" : "[hash:base64:8]", // invalid! for Unify getLocalIdent (Next.js / CRA), Cannot set it, but you can rewritten getLocalIdentFn
    exportLocalsConvention: "camelCase",
    exportOnlyLocals: false,
    // ...
    getLocalIdent: (context, localIdentName, localName, options) => {
      return "whatever_random_class_name";
    },
  },

  // for Next.js ONLY
  nextjs: {
    localIdentNameFollowDev: true, // default false, for easy to debug on PROD mode
  },

  // Other Config Here...

  webpack(config) {
    return config;
  },

  // ONLY for Next.js 10, if you use Next.js 11, delete this block
  future: {
    webpack5: true,
  },
});

Add a .babelrc.js

// .babelrc.js
module.exports = {
  presets: [['next/babel']],
  plugins: [['import', { libraryName: 'antd', style: true }]],
};

Detailed config can be found in next.config.js file.

for CRA / CRA-Co

const cracoPluginLess = require('next-plugin-antd-less/overrideWebpackConfig');

module.exports = {
  babel: cracoBabel,
  plugins: [
    cracoPluginAnalyze,
    {
      plugin: cracoPluginLess,
      options: {
        modifyVars: {
          '@THEME--DARK': 'theme-dark',
        },
        lessVarsFilePath: './src/styles/variables.less',
        cssLoaderOptions: {
          localIdentName: __DEV__ ? "[local]--[hash:base64:4]" : "[hash:base64:8]",
        },
      },
    },
  ],
};

Detailed config can be found in craco.config.js file.

FAQ

Reference Project?

If you have any problem, please check mkn (Next.js) and mkr (CRA) first, I update these two repo's every time I update this plugin.

Default ClassName

MODE className e.g.
DEV [local]--[hash:base64:4] comp-wrapper--2Rra
PROD [hash:base64:8] 2Rra8Ryx

for Unify getLocalIdent (Next.js / CRA), Cannot set it, but you can rewritten getLocalIdentFn

localIdentName is invalid? How to rewritten?

you can defind your own localIdentName in pluginOptions.cssLoaderOptions.modules.getLocalIdent

  options: {
  lessVarsFilePath: './src/styles/variables.less'
  // ...
  // https://github.com/webpack-contrib/css-loader/tree/b7a84414fb3f6e6ff413cbbb7004fa74a78da331#getlocalident
  //
  // and you can see file 
  // https://github.com/SolidZORO/next-plugin-antd-less/getCssModuleLocalIdent.js
  getLocalIdent: (context, _, exportName, options) => {
    return 'whatever_random_class_name';
  }
  // ...
}

How to import global CSS style (e.g. styles.css)?

// ./page/_app.tsx
//
// use `import` or `require` syntax,
import './styles.css';

How to import global Less style (e.g. styles.less)?

// ./page/_app.tsx
//
// use `require` syntax,
require('./styles.less');

How to overwrite antd less variables?

// ./src/styles/variables.less
@import '~antd/lib/style/themes/default.less'; // <-- you need to import antd variables once in your project

@primary-color: #04f; // change antd primary-color
// 🔰️ Tips: if your use babel import plugin and set `libraryDirectory`, please keep `libraryDirectory` and `less path` consistent.

// lib
['import', { libraryName: 'antd', libraryDirectory: 'lib', style: true }]
// `@import '~antd/lib/style/themes/default.less';` <-- use `lib`

// es
  ['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }]
// --> `@import '~antd/es/style/themes/default.less';` <-- use `es`
// plugin options
lessVarsFilePath: './src/styles/variables.less'

@seeMore issues #36, #74

Background

Issues

Since Next.js 9.3 supports sass and css by default, but does not support less. If you use Next.js > 9.3 and use the official less plugin, you will definitely encounter the following problems.

  1. CIL Warning Warning: Built-in CSS support is being disabled due to custom CSS configuration being detected.

  2. Does not support automatic recognition of css modules, e.g. a.module.less and a.less

Solution

  1. Find sassModule and copy onec and replace the sass-loader inside with less-loader.

  2. Then enable the modules.auto option of css-loader. This can simply match all *.less (no need to match it is *.module.less or *.less), and hand it over to css-loader.

This is the lowest cost way, And CLI will no longer show this disgusting warning. The important thing is that there is Zero Dependency on other Next-Plugins..

License

MIT © Jason Feng

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].