Less

Parcel 使用 @parcel/transformer-less 插件自动支持 Less 文件。当检测到 .less 文件时,它将自动安装到你的项目中。

¥Parcel supports Less files automatically using the @parcel/transformer-less plugin. When a .less file is detected, it will be installed into your project automatically.

Compiled Less 文件的处理方式也与 CSS 相同,这意味着它是针对你的浏览器目标进行编译的,并且还会应用任何 PostCSS 插件。还可以通过使用 .module.less 扩展名命名文件来使用 CSS 模块

¥Compiled Less files are also processed the same way as CSS, which means it is compiled for your browser targets, and any PostCSS plugins are also applied. CSS modules can also be used by naming your file with the .module.less extension.

用法示例

#

¥Example usage

在 HTML 文件中引用 Less 文件:

¥Referencing a Less file in an HTML file:

<link rel="stylesheet" href="style.less" />

在 JavaScript 或 TypeScript 中将 Less 文件导入为 CSS 模块:

¥Importing a Less file as a CSS module in JavaScript or TypeScript:

import * as classes from './style.module.less';

document.body.className = classes.body;

使用 Parcel CLI 直接编译 Less

¥Directly compiling Less using the Parcel CLI

parcel build style.less

配置

#

¥Configuration

要配置 Less,请创建一个 .lessrc 文件。要查看可用的配置选项,请参阅官方的 文档较少.Less。

¥To configure Less, create a .lessrc file. To see the available options to configure Less see the official Less documentation.

注意:基于 JavaScript 的配置也支持 .lessrc.js.lessrc.mjs.lessrc.cjs,但应尽可能避免,因为它会降低 Parcel 缓存的有效性。请改用基于 JSON 的配置格式(例如 .lessrc)。

¥Note: .lessrc.js, .lessrc.mjs, and .lessrc.cjs are also supported for JavaScript-based configuration, but should be avoided when possible because it reduces the effectiveness of Parcel's caching. Use a JSON based configuration format (e.g. .lessrc) instead.

Parcel 中文网 - 粤ICP备13048890号