Skip to content

Commit

Permalink
feat: paths now works with webpack resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito authored Apr 24, 2020
1 parent cecf183 commit 3931470
Show file tree
Hide file tree
Showing 68 changed files with 1,516 additions and 790 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ module.exports = {

#### Less resolver

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:
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:

**webpack.config.js**

Expand Down Expand Up @@ -443,8 +443,6 @@ module.exports = {
};
```

In this case, all webpack features like importing non-Less files or aliasing won't work of course.

### Plugins

In order to use [plugins](http://lesscss.org/usage/#plugins), simply set the
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"lint:prettier": "prettier --list-different .",
"lint:js": "eslint --cache .",
"lint": "npm-run-all -l -p \"lint:**\"",
"test:build": "node test/helpers/createSpec.js",
"test:only": "cross-env NODE_ENV=test npm run test:build && cross-env NODE_ENV=test jest",
"test:only": "cross-env NODE_ENV=test jest",
"test:watch": "npm run test:only -- --watch",
"test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
"pretest": "npm run lint",
Expand Down
4 changes: 1 addition & 3 deletions src/getLessOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ function getLessOptions(loaderContext, loaderOptions, content) {
data,
};

if (typeof lessOptions.paths === 'undefined') {
lessOptions.plugins.push(createWebpackLessPlugin(loaderContext));
}
lessOptions.plugins.push(createWebpackLessPlugin(loaderContext));

const useSourceMap =
typeof loaderOptions.sourceMap === 'boolean'
Expand Down
9 changes: 3 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { promisify } from 'util';

import less from 'less';

import { getOptions } from 'loader-utils';
Expand All @@ -10,10 +8,8 @@ import getLessOptions from './getLessOptions';
import removeSourceMappingUrl from './removeSourceMappingUrl';
import formatLessError from './formatLessError';

const render = promisify(less.render.bind(less));

function lessLoader(source) {
const options = getOptions(this) || {};
const options = getOptions(this);

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

render(lessOptions.data, lessOptions)
less
.render(lessOptions.data, lessOptions)
.then(({ css, map, imports }) => {
imports.forEach(this.addDependency, this);

Expand Down
23 changes: 23 additions & 0 deletions test/__snapshots__/appendData-option.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`appendData option should work append data as function: css 1`] = `
".background {
color: coral;
}
"
`;

exports[`appendData option should work append data as function: errors 1`] = `Array []`;

exports[`appendData option should work append data as function: warnings 1`] = `Array []`;

exports[`appendData option should work append data as string: css 1`] = `
".background {
color: coral;
}
"
`;

exports[`appendData option should work append data as string: errors 1`] = `Array []`;

exports[`appendData option should work append data as string: warnings 1`] = `Array []`;
37 changes: 0 additions & 37 deletions test/__snapshots__/index.test.js.snap

This file was deleted.

Loading

0 comments on commit 3931470

Please sign in to comment.