less-loader
Advanced tools
+10
-5
@@ -10,4 +10,2 @@ "use strict"; | ||
| var _less = _interopRequireDefault(require("less")); | ||
| var _options = _interopRequireDefault(require("./options.json")); | ||
@@ -24,6 +22,13 @@ | ||
| const callback = this.async(); | ||
| const implementation = (0, _utils.getLessImplementation)(this, options.implementation); | ||
| if (!implementation) { | ||
| callback(new Error(`The Less implementation "${options.implementation}" not found`)); | ||
| return; | ||
| } | ||
| const webpackContextSymbol = Symbol("loaderContext"); | ||
| const lessOptions = (0, _utils.getLessOptions)(this, { ...options, | ||
| webpackContextSymbol | ||
| }); | ||
| }, implementation); | ||
| const useSourceMap = typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap; | ||
@@ -46,3 +51,3 @@ | ||
| try { | ||
| result = await (options.implementation || _less.default).render(data, lessOptions); | ||
| result = await implementation.render(data, lessOptions); | ||
| } catch (error) { | ||
@@ -59,3 +64,3 @@ if (error.filename) { | ||
| delete _less.default[webpackContextSymbol]; | ||
| delete implementation[webpackContextSymbol]; | ||
| const { | ||
@@ -62,0 +67,0 @@ css, |
@@ -38,3 +38,10 @@ { | ||
| "description": "The implementation of the `Less` to be used (https://github.com/webpack-contrib/less-loader#implementation).", | ||
| "type": "object" | ||
| "anyOf": [ | ||
| { | ||
| "type": "string" | ||
| }, | ||
| { | ||
| "type": "object" | ||
| } | ||
| ] | ||
| } | ||
@@ -41,0 +48,0 @@ }, |
+27
-6
@@ -9,2 +9,3 @@ "use strict"; | ||
| exports.normalizeSourceMap = normalizeSourceMap; | ||
| exports.getLessImplementation = getLessImplementation; | ||
@@ -15,4 +16,2 @@ var _path = _interopRequireDefault(require("path")); | ||
| var _less = _interopRequireDefault(require("less")); | ||
| var _full = require("klona/full"); | ||
@@ -43,6 +42,7 @@ | ||
| * @param {LoaderContext} loaderContext | ||
| * @param {object} implementation | ||
| * @returns {LessPlugin} | ||
| */ | ||
| function createWebpackLessPlugin(loaderContext) { | ||
| function createWebpackLessPlugin(loaderContext, implementation) { | ||
| const resolve = loaderContext.getResolve({ | ||
@@ -57,3 +57,3 @@ dependencyType: "less", | ||
| class WebpackFileManager extends _less.default.FileManager { | ||
| class WebpackFileManager extends implementation.FileManager { | ||
| supports(filename) { | ||
@@ -164,2 +164,3 @@ if (filename[0] === "/" || IS_NATIVE_WIN32_PATH.test(filename)) { | ||
| * @param {object} loaderOptions | ||
| * @param {object} implementation | ||
| * @returns {Object} | ||
@@ -169,3 +170,3 @@ */ | ||
| function getLessOptions(loaderContext, loaderOptions) { | ||
| function getLessOptions(loaderContext, loaderOptions, implementation) { | ||
| const options = (0, _full.klona)(typeof loaderOptions.lessOptions === "function" ? loaderOptions.lessOptions(loaderContext) || {} : loaderOptions.lessOptions || {}); | ||
@@ -182,3 +183,3 @@ const lessOptions = { | ||
| if (shouldUseWebpackImporter) { | ||
| lessOptions.plugins.unshift(createWebpackLessPlugin(loaderContext)); | ||
| lessOptions.plugins.unshift(createWebpackLessPlugin(loaderContext, implementation)); | ||
| } | ||
@@ -235,2 +236,22 @@ | ||
| return newMap; | ||
| } | ||
| function getLessImplementation(loaderContext, implementation) { | ||
| let resolvedImplementation = implementation; | ||
| if (!implementation || typeof implementation === "string") { | ||
| const lessImplPkg = implementation || "less"; | ||
| try { | ||
| // eslint-disable-next-line import/no-dynamic-require, global-require | ||
| resolvedImplementation = require(lessImplPkg); | ||
| } catch (error) { | ||
| loaderContext.emitError(error); // eslint-disable-next-line consistent-return | ||
| return; | ||
| } | ||
| } // eslint-disable-next-line consistent-return | ||
| return resolvedImplementation; | ||
| } |
+12
-12
| { | ||
| "name": "less-loader", | ||
| "version": "9.0.0", | ||
| "version": "9.1.0", | ||
| "description": "A Less loader for webpack. Compiles Less to CSS.", | ||
@@ -24,3 +24,3 @@ "license": "MIT", | ||
| "commitlint": "commitlint --from=master", | ||
| "security": "npm audit", | ||
| "security": "npm audit --production", | ||
| "lint:prettier": "prettier --list-different .", | ||
@@ -34,3 +34,3 @@ "lint:js": "eslint --cache .", | ||
| "test": "npm run test:coverage", | ||
| "prepare": "npm run build", | ||
| "prepare": "husky install && npm run build", | ||
| "release": "standard-version" | ||
@@ -49,17 +49,17 @@ }, | ||
| "devDependencies": { | ||
| "@babel/cli": "^7.13.16", | ||
| "@babel/core": "^7.14.2", | ||
| "@babel/preset-env": "^7.14.2", | ||
| "@babel/cli": "^7.14.5", | ||
| "@babel/core": "^7.14.5", | ||
| "@babel/preset-env": "^7.14.5", | ||
| "@commitlint/cli": "^12.1.4", | ||
| "@commitlint/config-conventional": "^12.1.4", | ||
| "@webpack-contrib/eslint-config-webpack": "^3.0.0", | ||
| "babel-jest": "^26.6.3", | ||
| "babel-jest": "^27.0.2", | ||
| "cross-env": "^7.0.3", | ||
| "del": "^6.0.0", | ||
| "del-cli": "^3.0.1", | ||
| "eslint": "^7.26.0", | ||
| "eslint": "^7.28.0", | ||
| "eslint-config-prettier": "^8.3.0", | ||
| "eslint-plugin-import": "^2.22.1", | ||
| "eslint-plugin-import": "^2.23.4", | ||
| "husky": "^6.0.0", | ||
| "jest": "^26.6.3", | ||
| "jest": "^27.0.4", | ||
| "less": "^4.1.1", | ||
@@ -69,6 +69,6 @@ "lint-staged": "^11.0.0", | ||
| "npm-run-all": "^4.1.5", | ||
| "prettier": "^2.3.0", | ||
| "prettier": "^2.3.1", | ||
| "standard-version": "^9.3.0", | ||
| "strip-ansi": "^7.0.0", | ||
| "webpack": "^5.37.0" | ||
| "webpack": "^5.38.1" | ||
| }, | ||
@@ -75,0 +75,0 @@ "keywords": [ |
+30
-2
@@ -59,3 +59,3 @@ <div align="center"> | ||
| | **[`webpackImporter`](#webpackimporter)** | `{Boolean}` | `true` | Enables/Disables the default Webpack importer. | | ||
| | **[`implementation`](#implementation)** | `{Object}` | `less` | Setup Less implementation to use. | | ||
| | **[`implementation`](#implementation)** | `{Object\|String}` | `less` | Setup Less implementation to use. | | ||
@@ -320,3 +320,3 @@ ### `lessOptions` | ||
| Type: `Object` | ||
| Type: `Object | String` | ||
@@ -329,2 +329,4 @@ > ⚠ less-loader compatible with Less 3 and 4 versions | ||
| #### Object | ||
| **webpack.config.js** | ||
@@ -354,2 +356,28 @@ | ||
| #### String | ||
| **webpack.config.js** | ||
| ```js | ||
| module.exports = { | ||
| module: { | ||
| rules: [ | ||
| { | ||
| test: /\.less$/i, | ||
| use: [ | ||
| "style-loader", | ||
| "css-loader", | ||
| { | ||
| loader: "less-loader", | ||
| options: { | ||
| implementation: require.resolve("less"), | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| }; | ||
| ``` | ||
| ## Examples | ||
@@ -356,0 +384,0 @@ |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
33217
4.34%331
8.88%612
4.79%7
16.67%