Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

less-loader

Package Overview
Dependencies
Maintainers
8
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

less-loader - npm Package Compare versions

Comparing version 7.0.2 to 7.1.0

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [7.1.0](https://github.com/webpack-contrib/less-loader/compare/v7.0.2...v7.1.0) (2020-11-11)
### Features
* allow the `additionalData` to be async ([#391](https://github.com/webpack-contrib/less-loader/issues/391)) ([62c6934](https://github.com/webpack-contrib/less-loader/commit/62c6934367eb4dd0d4f3155ed2bb5f3e065aafba))
### [7.0.2](https://github.com/webpack-contrib/less-loader/compare/v7.0.1...v7.0.2) (2020-10-09)

@@ -7,0 +14,0 @@

2

dist/cjs.js
"use strict";
module.exports = require('./index').default;
module.exports = require("./index").default;

@@ -27,8 +27,8 @@ "use strict";

(0, _schemaUtils.validate)(_options.default, options, {
name: 'Less Loader',
baseDataPath: 'options'
name: "Less Loader",
baseDataPath: "options"
});
const callback = this.async();
const lessOptions = (0, _utils.getLessOptions)(this, options);
const useSourceMap = typeof options.sourceMap === 'boolean' ? options.sourceMap : this.sourceMap;
const useSourceMap = typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap;

@@ -43,4 +43,4 @@ if (useSourceMap) {

if (typeof options.additionalData !== 'undefined') {
data = typeof options.additionalData === 'function' ? `${options.additionalData(data, this)}` : `${options.additionalData}\n${data}`;
if (typeof options.additionalData !== "undefined") {
data = typeof options.additionalData === "function" ? `${await options.additionalData(data, this)}` : `${options.additionalData}\n${data}`;
}

@@ -76,3 +76,3 @@

});
let map = typeof result.map === 'string' ? JSON.parse(result.map) : result.map;
let map = typeof result.map === "string" ? JSON.parse(result.map) : result.map;

@@ -79,0 +79,0 @@ if (map && useSourceMap) {

@@ -15,3 +15,3 @@ "use strict";

super();
this.message = ['\n', ...LessError.getFileExcerptIfPossible(error), error.message.charAt(0).toUpperCase() + error.message.slice(1), ` Error in ${_path.default.normalize(error.filename)} (line ${error.line}, column ${error.column})`].join('\n');
this.message = ["\n", ...LessError.getFileExcerptIfPossible(error), error.message.charAt(0).toUpperCase() + error.message.slice(1), ` Error in ${_path.default.normalize(error.filename)} (line ${error.line}, column ${error.column})`].join("\n");
this.hideStack = true;

@@ -21,3 +21,3 @@ }

static getFileExcerptIfPossible(lessError) {
if (typeof lessError.extract === 'undefined') {
if (typeof lessError.extract === "undefined") {
return [];

@@ -29,7 +29,7 @@ }

if (typeof excerpt[0] === 'undefined') {
if (typeof excerpt[0] === "undefined") {
excerpt.shift();
}
excerpt.push(`${new Array(column).join(' ')}^`);
excerpt.push(`${new Array(column).join(" ")}^`);
return excerpt;

@@ -36,0 +36,0 @@ }

@@ -37,6 +37,6 @@ "use strict";

const resolve = loaderContext.getResolve({
conditionNames: ['less', 'style'],
mainFields: ['less', 'style', 'main', '...'],
mainFiles: ['index', '...'],
extensions: ['.less', '.css']
conditionNames: ["less", "style"],
mainFields: ["less", "style", "main", "..."],
mainFiles: ["index", "..."],
extensions: [".less", ".css"]
});

@@ -46,3 +46,3 @@

supports(filename) {
if (filename[0] === '/' || IS_NATIVE_WIN32_PATH.test(filename)) {
if (filename[0] === "/" || IS_NATIVE_WIN32_PATH.test(filename)) {
return true;

@@ -69,5 +69,5 @@ }

// Less is giving us trailing slashes, but the context should have no trailing slash
const context = currentDirectory.replace(trailingSlash, '');
const context = currentDirectory.replace(trailingSlash, "");
const request = (0, _loaderUtils.urlToRequest)(filename, // eslint-disable-next-line no-undefined
filename.charAt(0) === '/' ? loaderContext.rootContext : undefined);
filename.charAt(0) === "/" ? loaderContext.rootContext : undefined);
return this.resolveRequests(context, [...new Set([request, filename])]);

@@ -100,3 +100,3 @@ }

const error = new Error();
error.type = 'Next';
error.type = "Next";
throw error;

@@ -107,3 +107,3 @@ }

} catch (error) {
if (error.type !== 'File' && error.type !== 'Next') {
if (error.type !== "File" && error.type !== "Next") {
return Promise.reject(error);

@@ -147,3 +147,3 @@ }

function getLessOptions(loaderContext, loaderOptions) {
const options = (0, _full.klona)(typeof loaderOptions.lessOptions === 'function' ? loaderOptions.lessOptions(loaderContext) || {} : loaderOptions.lessOptions || {});
const options = (0, _full.klona)(typeof loaderOptions.lessOptions === "function" ? loaderOptions.lessOptions(loaderContext) || {} : loaderOptions.lessOptions || {});
const lessOptions = {

@@ -156,3 +156,3 @@ plugins: [],

};
const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === 'boolean' ? loaderOptions.webpackImporter : true;
const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === "boolean" ? loaderOptions.webpackImporter : true;

@@ -191,3 +191,3 @@ if (shouldUseWebpackImporter) {

newMap.sourceRoot = ''; // `less` returns POSIX paths, that's why we need to transform them back to native paths.
newMap.sourceRoot = ""; // `less` returns POSIX paths, that's why we need to transform them back to native paths.
// eslint-disable-next-line no-param-reassign

@@ -194,0 +194,0 @@

{
"name": "less-loader",
"version": "7.0.2",
"version": "7.1.0",
"description": "A Less loader for webpack. Compiles Less to CSS.",

@@ -50,5 +50,5 @@ "license": "MIT",

"devDependencies": {
"@babel/cli": "^7.11.6",
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@commitlint/cli": "^11.0.0",

@@ -62,11 +62,10 @@ "@commitlint/config-conventional": "^11.0.0",

"del-cli": "^3.0.1",
"eslint": "^7.10.0",
"eslint-config-prettier": "^6.12.0",
"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.1.4",
"husky": "^4.3.0",
"inspect-loader": "^1.0.0",
"jest": "^26.5.2",
"jest": "^26.6.3",
"less": "^3.12.2",
"lint-staged": "^10.4.0",
"lint-staged": "^10.5.1",
"memfs": "^3.2.0",

@@ -77,3 +76,3 @@ "npm-run-all": "^4.1.5",

"strip-ansi": "^6.0.0",
"webpack": "^4.44.2"
"webpack": "^5.4.0"
},

@@ -80,0 +79,0 @@ "keywords": [

@@ -37,3 +37,3 @@ <div align="center">

test: /\.less$/,
loader: 'less-loader', // compiles Less to CSS
loader: "less-loader", // compiles Less to CSS
},

@@ -77,9 +77,9 @@ ],

{
loader: 'style-loader',
loader: "style-loader",
},
{
loader: 'css-loader',
loader: "css-loader",
},
{
loader: 'less-loader',
loader: "less-loader",
options: {

@@ -109,6 +109,6 @@ lessOptions: {

use: [
'style-loader',
'css-loader',
"style-loader",
"css-loader",
{
loader: 'less-loader',
loader: "less-loader",
options: {

@@ -120,5 +120,5 @@ lessOptions: (loaderContext) => {

if (relativePath === 'styles/foo.less') {
if (relativePath === "styles/foo.less") {
return {
paths: ['absolute/path/c', 'absolute/path/d'],
paths: ["absolute/path/c", "absolute/path/d"],
};

@@ -128,3 +128,3 @@ }

return {
paths: ['absolute/path/a', 'absolute/path/b'],
paths: ["absolute/path/a", "absolute/path/b"],
};

@@ -162,6 +162,6 @@ },

use: [
'style-loader',
'css-loader',
"style-loader",
"css-loader",
{
loader: 'less-loader',
loader: "less-loader",
options: {

@@ -180,2 +180,4 @@ additionalData: `@env: ${process.env.NODE_ENV};`,

##### Sync
```js

@@ -188,6 +190,6 @@ module.exports = {

use: [
'style-loader',
'css-loader',
"style-loader",
"css-loader",
{
loader: 'less-loader',
loader: "less-loader",
options: {

@@ -199,7 +201,7 @@ additionalData: (content, loaderContext) => {

if (relativePath === 'styles/foo.less') {
return '@value: 100px;' + content;
if (relativePath === "styles/foo.less") {
return "@value: 100px;" + content;
}
return '@value: 200px;' + content;
return "@value: 200px;" + content;
},

@@ -215,2 +217,36 @@ },

##### Async
```js
module.exports = {
module: {
rules: [
{
test: /\.less$/,
use: [
"style-loader",
"css-loader",
{
loader: "less-loader",
options: {
additionalData: async (content, loaderContext) => {
// More information about available properties https://webpack.js.org/api/loaders/
const { resourcePath, rootContext } = loaderContext;
const relativePath = path.relative(rootContext, resourcePath);
if (relativePath === "styles/foo.less") {
return "@value: 100px;" + content;
}
return "@value: 200px;" + content;
},
},
},
],
},
],
},
};
```
### `sourceMap`

@@ -232,5 +268,5 @@

use: [
'style-loader',
"style-loader",
{
loader: 'css-loader',
loader: "css-loader",
options: {

@@ -241,3 +277,3 @@ sourceMap: true,

{
loader: 'less-loader',
loader: "less-loader",
options: {

@@ -272,6 +308,6 @@ sourceMap: true,

use: [
'style-loader',
'css-loader',
"style-loader",
"css-loader",
{
loader: 'less-loader',
loader: "less-loader",
options: {

@@ -304,9 +340,9 @@ webpackImporter: false,

{
loader: 'style-loader', // creates style nodes from JS strings
loader: "style-loader", // creates style nodes from JS strings
},
{
loader: 'css-loader', // translates CSS into CommonJS
loader: "css-loader", // translates CSS into CommonJS
},
{
loader: 'less-loader', // compiles Less to CSS
loader: "less-loader", // compiles Less to CSS
},

@@ -330,3 +366,3 @@ ],

module.exports = {
devtool: 'source-map', // any "source-map"-like devtool is possible
devtool: "source-map", // any "source-map"-like devtool is possible
module: {

@@ -337,5 +373,5 @@ rules: [

use: [
'style-loader',
"style-loader",
{
loader: 'css-loader',
loader: "css-loader",
options: {

@@ -346,3 +382,3 @@ sourceMap: true,

{
loader: 'less-loader',
loader: "less-loader",
options: {

@@ -374,3 +410,3 @@ sourceMap: true,

```css
@import '~bootstrap/less/bootstrap';
@import "~bootstrap/less/bootstrap";
```

@@ -380,25 +416,2 @@

##### Non-Less imports
Using webpack's resolver, you can import any file type. You just need a loader that exports valid Less code. Often, you will also want to set the `issuer` condition to ensure that this rule is only applied on imports originating from Less files:
```js
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
issuer: /\.less$/,
use: [
{
loader: 'js-to-less-loader',
},
],
},
],
},
};
```
#### Less resolver

@@ -418,12 +431,12 @@

{
loader: 'style-loader',
loader: "style-loader",
},
{
loader: 'css-loader',
loader: "css-loader",
},
{
loader: 'less-loader',
loader: "less-loader",
options: {
lessOptions: {
paths: [path.resolve(__dirname, 'node_modules')],
paths: [path.resolve(__dirname, "node_modules")],
},

@@ -468,3 +481,3 @@ },

install: function (less, pluginManager, functions) {
functions.add('pi', function () {
functions.add("pi", function () {
// Loader context is available in `less.webpackLoaderContext`

@@ -471,0 +484,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc