less-loader
Advanced tools
Comparing version 7.3.0 to 8.0.0
@@ -5,2 +5,20 @@ # Changelog | ||
## [8.0.0](https://github.com/webpack-contrib/less-loader/compare/v7.3.0...v8.0.0) (2021-02-01) | ||
### Notes | ||
* using `~` is deprecated and can be removed from your code (**we recommend it**), but we still support it for historical reasons. | ||
Why you can removed it? | ||
The loader will first try to resolve `@import` as relative, if it cannot be resolved, the loader will try to resolve `@import` inside [`node_modules`](https://webpack.js.org/configuration/resolve/#resolve-modules). | ||
### ⚠ BREAKING CHANGES | ||
* minimum supported `webpack` version is `5` | ||
### Features | ||
* supported the [`resolve.byDependency`](https://webpack.js.org/configuration/resolve/#resolvebydependency) option, you can setup `{ resolve: { byDependency: { less: { mainFiles: ['custom', '...'] } } } }` | ||
## [7.3.0](https://github.com/webpack-contrib/less-loader/compare/v7.2.1...v7.3.0) (2021-01-21) | ||
@@ -7,0 +25,0 @@ |
@@ -12,6 +12,2 @@ "use strict"; | ||
var _loaderUtils = require("loader-utils"); | ||
var _schemaUtils = require("schema-utils"); | ||
var _options = _interopRequireDefault(require("./options.json")); | ||
@@ -26,7 +22,3 @@ | ||
async function lessLoader(source) { | ||
const options = (0, _loaderUtils.getOptions)(this); | ||
(0, _schemaUtils.validate)(_options.default, options, { | ||
name: "Less Loader", | ||
baseDataPath: "options" | ||
}); | ||
const options = this.getOptions(_options.default); | ||
const callback = this.async(); | ||
@@ -33,0 +25,0 @@ const lessOptions = (0, _utils.getLessOptions)(this, options); |
{ | ||
"title": "Less Loader options", | ||
"type": "object", | ||
@@ -3,0 +4,0 @@ "properties": { |
@@ -16,4 +16,2 @@ "use strict"; | ||
var _loaderUtils = require("loader-utils"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -28,3 +26,12 @@ | ||
const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i; | ||
const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i; // Examples: | ||
// - ~package | ||
// - ~package/ | ||
// - ~@org | ||
// - ~@org/ | ||
// - ~@org/package | ||
// - ~@org/package/ | ||
const IS_MODULE_IMPORT = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+\/)$/; | ||
const MODULE_REQUEST_REGEX = /^[^?]*~/; | ||
/** | ||
@@ -39,6 +46,8 @@ * Creates a Less plugin that uses webpack's resolving engine that is provided by the loaderContext. | ||
const resolve = loaderContext.getResolve({ | ||
dependencyType: "less", | ||
conditionNames: ["less", "style"], | ||
mainFields: ["less", "style", "main", "..."], | ||
mainFiles: ["index", "..."], | ||
extensions: [".less", ".css"] | ||
extensions: [".less", ".css"], | ||
preferRelative: true | ||
}); | ||
@@ -71,8 +80,16 @@ | ||
const context = currentDirectory.replace(trailingSlash, ""); | ||
const request = (0, _loaderUtils.urlToRequest)(filename, // eslint-disable-next-line no-undefined | ||
filename.charAt(0) === "/" ? loaderContext.rootContext : undefined); | ||
let request = filename; // A `~` makes the url an module | ||
if (MODULE_REQUEST_REGEX.test(filename)) { | ||
request = request.replace(MODULE_REQUEST_REGEX, ""); | ||
} | ||
if (IS_MODULE_IMPORT.test(filename)) { | ||
request = request[request.length - 1] === "/" ? request : `${request}/`; | ||
} | ||
return this.resolveRequests(context, [...new Set([request, filename])]); | ||
} | ||
resolveRequests(context, possibleRequests) { | ||
async resolveRequests(context, possibleRequests) { | ||
if (possibleRequests.length === 0) { | ||
@@ -82,3 +99,7 @@ return Promise.reject(); | ||
return resolve(context, possibleRequests[0]).then(result => result).catch(error => { | ||
let result; | ||
try { | ||
result = await resolve(context, possibleRequests[0]); | ||
} catch (error) { | ||
const [, ...tailPossibleRequests] = possibleRequests; | ||
@@ -90,4 +111,6 @@ | ||
return this.resolveRequests(context, tailPossibleRequests); | ||
}); | ||
result = await this.resolveRequests(context, tailPossibleRequests); | ||
} | ||
return result; | ||
} | ||
@@ -94,0 +117,0 @@ |
{ | ||
"name": "less-loader", | ||
"version": "7.3.0", | ||
"version": "8.0.0", | ||
"description": "A Less loader for webpack. Compiles Less to CSS.", | ||
@@ -42,8 +42,6 @@ "license": "MIT", | ||
"less": "^3.5.0 || ^4.0.0", | ||
"webpack": "^4.0.0 || ^5.0.0" | ||
"webpack": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"klona": "^2.0.4", | ||
"loader-utils": "^2.0.0", | ||
"schema-utils": "^3.0.0" | ||
"klona": "^2.0.4" | ||
}, | ||
@@ -62,3 +60,3 @@ "devDependencies": { | ||
"del-cli": "^3.0.1", | ||
"eslint": "^7.18.0", | ||
"eslint": "^7.19.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
@@ -69,3 +67,3 @@ "eslint-plugin-import": "^2.22.1", | ||
"jest": "^26.6.3", | ||
"less": "^4.1.0", | ||
"less": "^4.1.1", | ||
"lint-staged": "^10.5.3", | ||
@@ -77,3 +75,3 @@ "memfs": "^3.2.0", | ||
"strip-ansi": "^6.0.0", | ||
"webpack": "^5.16.0" | ||
"webpack": "^5.19.0" | ||
}, | ||
@@ -80,0 +78,0 @@ "keywords": [ |
@@ -284,3 +284,3 @@ <div align="center"> | ||
Enables/Disables the default Webpack importer. | ||
Enables/Disables the default `webpack` importer. | ||
@@ -386,3 +386,3 @@ This can improve performance in some cases. Use it with caution because aliases and `@import` at-rules starting with `~` will not work. | ||
```javascript | ||
```js | ||
module.exports = { | ||
@@ -423,17 +423,53 @@ devtool: "source-map", // any "source-map"-like devtool is possible | ||
Starting with `less-loader` 4, you can now choose between Less' builtin resolver and webpack's resolver. By default, webpack's resolver is used. | ||
First we try to use built-in `less` resolve logic, then `webpack` resolve logic (aliases and `~`). | ||
#### webpack resolver | ||
#### Webpack Resolver | ||
webpack provides an [advanced mechanism to resolve files](https://webpack.js.org/configuration/resolve/). The `less-loader` applies a Less plugin that passes all queries to the webpack resolver. Thus you can import your Less modules from `node_modules`. Just prepend them with a `~` which tells webpack to look up the [`modules`](https://webpack.js.org/configuration/resolve/#resolve-modules). | ||
`webpack` provides an [advanced mechanism to resolve files](https://webpack.js.org/configuration/resolve/). | ||
`less-loader` applies a Less plugin that passes all queries to the webpack resolver if `less` could not resolve `@import`. | ||
Thus you can import your Less modules from `node_modules`. | ||
```css | ||
@import "bootstrap/less/bootstrap"; | ||
``` | ||
Using `~` is deprecated and can be removed from your code (**we recommend it**), but we still support it for historical reasons. | ||
Why you can removed it? The loader will first try to resolve `@import` as relative, if it cannot be resolved, the loader will try to resolve `@import` inside [`node_modules`](https://webpack.js.org/configuration/resolve/#resolve-modules). | ||
Just prepend them with a `~` which tells webpack to look up the [`modules`](https://webpack.js.org/configuration/resolve/#resolve-modules). | ||
```css | ||
@import "~bootstrap/less/bootstrap"; | ||
``` | ||
Default resolver options can be modified by [`resolve.byDependency`](https://webpack.js.org/configuration/resolve/#resolvebydependency): | ||
**webpack.config.js** | ||
```js | ||
module.exports = { | ||
devtool: "source-map", // any "source-map"-like devtool is possible | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.less$/i, | ||
use: ["style-loader", "css-loader", "less-loader"], | ||
}, | ||
], | ||
}, | ||
resolve: { | ||
byDependency: { | ||
// More options can be found here https://webpack.js.org/configuration/resolve/ | ||
less: { | ||
mainFiles: ["custom"], | ||
}, | ||
}, | ||
}, | ||
}; | ||
``` | ||
It's important to only prepend it with `~`, because `~/` resolves to the home-directory. webpack needs to distinguish between `bootstrap` and `~bootstrap`, because CSS and Less files have no special syntax for importing relative files. Writing `@import "file"` is the same as `@import "./file";` | ||
#### Less resolver | ||
#### Less Resolver | ||
If you specify the `paths` option, modules will be searched in the given `paths`. This is Less' default behavior. `paths` should be an array with absolute paths: | ||
If you specify the `paths` option, modules will be searched in the given `paths`. This is `less` default behavior. `paths` should be an array with absolute paths: | ||
@@ -474,4 +510,5 @@ **webpack.config.js** | ||
**webpack.config.js** | ||
```js | ||
// webpack.config.js | ||
const CleanCSSPlugin = require('less-plugin-clean-css'); | ||
@@ -478,0 +515,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44863
3
288
579
+ Added@webassemblyjs/ast@1.14.1(transitive)
+ Added@webassemblyjs/floating-point-hex-parser@1.13.2(transitive)
+ Added@webassemblyjs/helper-api-error@1.13.2(transitive)
+ Added@webassemblyjs/helper-buffer@1.14.1(transitive)
+ Added@webassemblyjs/helper-numbers@1.13.2(transitive)
+ Added@webassemblyjs/helper-wasm-bytecode@1.13.2(transitive)
+ Added@webassemblyjs/helper-wasm-section@1.14.1(transitive)
+ Added@webassemblyjs/ieee754@1.13.2(transitive)
+ Added@webassemblyjs/leb128@1.13.2(transitive)
+ Added@webassemblyjs/utf8@1.13.2(transitive)
+ Added@webassemblyjs/wasm-edit@1.14.1(transitive)
+ Added@webassemblyjs/wasm-gen@1.14.1(transitive)
+ Added@webassemblyjs/wasm-opt@1.14.1(transitive)
+ Added@webassemblyjs/wasm-parser@1.14.1(transitive)
+ Added@webassemblyjs/wast-printer@1.14.1(transitive)
+ Addedcaniuse-lite@1.0.30001679(transitive)
+ Addedelectron-to-chromium@1.5.55(transitive)
- Removedloader-utils@^2.0.0
- Removedschema-utils@^3.0.0
- Removed@webassemblyjs/ast@1.12.1(transitive)
- Removed@webassemblyjs/floating-point-hex-parser@1.11.6(transitive)
- Removed@webassemblyjs/helper-api-error@1.11.6(transitive)
- Removed@webassemblyjs/helper-buffer@1.12.1(transitive)
- Removed@webassemblyjs/helper-numbers@1.11.6(transitive)
- Removed@webassemblyjs/helper-wasm-bytecode@1.11.6(transitive)
- Removed@webassemblyjs/helper-wasm-section@1.12.1(transitive)
- Removed@webassemblyjs/ieee754@1.11.6(transitive)
- Removed@webassemblyjs/leb128@1.11.6(transitive)
- Removed@webassemblyjs/utf8@1.11.6(transitive)
- Removed@webassemblyjs/wasm-edit@1.12.1(transitive)
- Removed@webassemblyjs/wasm-gen@1.12.1(transitive)
- Removed@webassemblyjs/wasm-opt@1.12.1(transitive)
- Removed@webassemblyjs/wasm-parser@1.12.1(transitive)
- Removed@webassemblyjs/wast-printer@1.12.1(transitive)
- Removedbig.js@5.2.2(transitive)
- Removedcaniuse-lite@1.0.30001677(transitive)
- Removedelectron-to-chromium@1.5.51(transitive)
- Removedemojis-list@3.0.0(transitive)
- Removedjson5@2.2.3(transitive)
- Removedloader-utils@2.0.4(transitive)