Skip to content

Commit 3931470

Browse files
feat: paths now works with webpack resolver
1 parent cecf183 commit 3931470

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1516
-790
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ module.exports = {
411411

412412
#### Less resolver
413413

414-
If you specify the `paths` option, the `less-loader` will not use webpack's resolver. Modules, that can't be resolved in the local folder, will be searched in the given `paths`. This is Less' default behavior. `paths` should be an array with absolute paths:
414+
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:
415415

416416
**webpack.config.js**
417417

@@ -443,8 +443,6 @@ module.exports = {
443443
};
444444
```
445445

446-
In this case, all webpack features like importing non-Less files or aliasing won't work of course.
447-
448446
### Plugins
449447

450448
In order to use [plugins](http://lesscss.org/usage/#plugins), simply set the

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
"lint:prettier": "prettier --list-different .",
2626
"lint:js": "eslint --cache .",
2727
"lint": "npm-run-all -l -p \"lint:**\"",
28-
"test:build": "node test/helpers/createSpec.js",
29-
"test:only": "cross-env NODE_ENV=test npm run test:build && cross-env NODE_ENV=test jest",
28+
"test:only": "cross-env NODE_ENV=test jest",
3029
"test:watch": "npm run test:only -- --watch",
3130
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
3231
"pretest": "npm run lint",

src/getLessOptions.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ function getLessOptions(loaderContext, loaderOptions, content) {
5252
data,
5353
};
5454

55-
if (typeof lessOptions.paths === 'undefined') {
56-
lessOptions.plugins.push(createWebpackLessPlugin(loaderContext));
57-
}
55+
lessOptions.plugins.push(createWebpackLessPlugin(loaderContext));
5856

5957
const useSourceMap =
6058
typeof loaderOptions.sourceMap === 'boolean'

src/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { promisify } from 'util';
2-
31
import less from 'less';
42

53
import { getOptions } from 'loader-utils';
@@ -10,10 +8,8 @@ import getLessOptions from './getLessOptions';
108
import removeSourceMappingUrl from './removeSourceMappingUrl';
119
import formatLessError from './formatLessError';
1210

13-
const render = promisify(less.render.bind(less));
14-
1511
function lessLoader(source) {
16-
const options = getOptions(this) || {};
12+
const options = getOptions(this);
1713

1814
validateOptions(schema, options, {
1915
name: 'Less Loader',
@@ -23,7 +19,8 @@ function lessLoader(source) {
2319
const callback = this.async();
2420
const lessOptions = getLessOptions(this, options, source);
2521

26-
render(lessOptions.data, lessOptions)
22+
less
23+
.render(lessOptions.data, lessOptions)
2724
.then(({ css, map, imports }) => {
2825
imports.forEach(this.addDependency, this);
2926

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`appendData option should work append data as function: css 1`] = `
4+
".background {
5+
color: coral;
6+
}
7+
"
8+
`;
9+
10+
exports[`appendData option should work append data as function: errors 1`] = `Array []`;
11+
12+
exports[`appendData option should work append data as function: warnings 1`] = `Array []`;
13+
14+
exports[`appendData option should work append data as string: css 1`] = `
15+
".background {
16+
color: coral;
17+
}
18+
"
19+
`;
20+
21+
exports[`appendData option should work append data as string: errors 1`] = `Array []`;
22+
23+
exports[`appendData option should work append data as string: warnings 1`] = `Array []`;

test/__snapshots__/index.test.js.snap

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)