• Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 3 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Next.js + Less CSS Support

next-with-less

Next.js + Less CSS Support

Next.js supports SASS/SCSS, but not Less. This plugin adds Less support by duplicating SASS webpack rules and adding support for .less files with less-loader. It mimics the exact behavior of CSS extraction/css-modules/errors/client/server of SASS.

โš ๏ธ Use with caution - Next.js implementation can change in any version, and the monkey patching may not work anymore.

Install

Compatiblilty:

  • Next 11, 12 -> v2.x
  • Next 13.3+ -> v3.x
yarn add next-with-less

npm i next-with-less

Peer dependencies to install: less less-loader.

Usage

// next.config.js
const withLess = require("next-with-less");

module.exports = withLess({
  lessLoaderOptions: {
    /* ... */
  },
});

You can see all the options available to less-loader here.

Usage with next-compose-plugins

// next.config.js
const withPlugins = require("next-compose-plugins");

const withLess = require("next-with-less");

const plugins = [
  /* ...other plugins... */
  [withLess, {
    lessLoaderOptions: {
      /* ... */
    },
  }],
  /* ...other plugins... */
];

module.exports = withPlugins(plugins, {
  /* ... */
});

Customize antd theme

To override some of antd default variables, just add them under lessLoaderOptions.lessOptions.modifyVars:

// next.config.js
const withLess = require("next-with-less");

module.exports = withLess({
  lessLoaderOptions: {
    /* ... */
    lessOptions: {
      /* ... */
      modifyVars: {
        "primary-color": "#9900FF",
        "border-radius-base": "2px",
        /* ... */
      },
    },
  },
});

As an alternative, the same can be achieved using the additionalData option. Put your variables in a file, like:

@primary-color: #9900ff;
@border-radius-base: 2px;

and then pass it to less-loader using additionalData:

// next.config.js
const withLess = require("next-with-less");
const path = require("path");

const pathToLessFileWithVariables = path.resolve(
  "your-file-with-antd-variables.less"
);

module.exports = withLess({
  lessLoaderOptions: {
    /* ... */
    additionalData: (content) =>
      `${content}\n\n@import '${pathToLessFileWithVariables}';`,
  },
});

There's an existing PR trying to add built in Less support for Next, but currently it's not likely to be merged.

More Repositories

1

jastor

Auto translates NSDictionary to instances of Objective-C classes, supporting nested types and arrays
Objective-C
344
star
2

reuse-promise

Reuse the same promise that's returned from a function until it's resolved
JavaScript
103
star
3

isotope

Ruby Hybrid Template Engine for Client Side and Server Side, EJS-Based
Ruby
55
star
4

lodash-bound

Enables chained lodash functions with ES bind (::) syntax
JavaScript
39
star
5

class-private-method-decorator

Private methods in a JavaScript ES6 class using an ES7 decorator
JavaScript
30
star
6

rollup-plugin-preserve-shebangs

A Rollup plugin that preserves shebangs (#!/usr/bin/env node) in output files
TypeScript
17
star
7

hoist-non-react-methods

Copies non-react specific methods from a child component to a parent component
JavaScript
11
star
8

kaching

Makes your DB suffer less from COUNT(*) queries and check-for-existence queries of associations (has_many and has_many :through), by keeping and maintaining counts and lists on Redis, for faster access.
Ruby
7
star
9

sidekiq_custom_serializer

An extension for Sidekiq that brings custom serialization of arguments such as ActiveRecord instances, classes, modules and custom objects.
Ruby
3
star
10

mootools-trackinstances

Track Class Instances With a Class Mutator
JavaScript
2
star
11

fake-https-cert

JavaScript
1
star
12

react-ref-method-forwarder

Allows accessing methods of HOC-wrapped components through normal React refs
JavaScript
1
star
13

barcode

JavaScript
1
star
14

mootools-laziness

Class Mutator to reduce memory usage of class' prototype objects and function pointers unless an instance is instantiated
JavaScript
1
star