3.0.1 • Published 12 months ago

next-with-less v3.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

next-with-less

Next.js + Less CSS Support

Hopefully this plugin will be unnecessary soon - when https://github.com/vercel/next.js/pull/23185 merges

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 chance in any version, and the monkey patching may not work anymore.

Tested with next@11.0.1 with webpack@5, and antd@4.15.x.

Install

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 = [
  withLess,
  {
    lessLoaderOptions: {
      /* ... */
    },
  },
];

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}';`,
  },
});
3.0.1

12 months ago

3.0.0

12 months ago

2.0.3

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.0-beta.1

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago