Coder Social home page Coder Social logo

dryleaf / next-plugin-antd-less Goto Github PK

View Code? Open in Web Editor NEW

This project forked from solidzoro/next-plugin-antd-less

0.0 1.0 0.0 85 KB

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

License: MIT License

JavaScript 100.00%

next-plugin-antd-less's Introduction

Next.js + Antd (with Less)

NPM version License: MIT

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

๐Ÿ“Œ Demo w/ Next.js v10

Introduction

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..

Installation

yarn add next-plugin-antd-less

Usage

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

module.exports = withAntdLess({
  // optional
  modifyVars: { '@primary-color': '#04f' },
  // optional
  lessVarsFilePath: './src/styles/variables.less',
  // optional https://github.com/webpack-contrib/css-loader#object
  cssLoaderOptions: {},
  
  // Other Config Here...

  webpack(config) {
    return config;
  },
});

Add a .babelrc.js

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

Tips

  • If you need to import the global CSS (e.g. styles.css), you can write in _app.tsx,
// ./page/_app.tsx
import './styles.css';
  • If you need to import the global Less (e.g. styles.less), you can use require syntax,
// ./page/index.tsx
require('./styles.less');

Compatibility

  • next 9.3.0+
  • less v4.0.0+
  • less v3.0.0+

License

ยฉ MIT

next-plugin-antd-less's People

Contributors

richmonkeys avatar shian15810 avatar solidzoro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.