Skip to content

Commit c19446d

Browse files
authored
docs: update readme.md (#3)
1 parent 700ba3c commit c19446d

File tree

9 files changed

+1646
-15
lines changed

9 files changed

+1646
-15
lines changed

.github/workflows/node.js.yml renamed to .github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ jobs:
2424
- name: Checkout
2525
uses: actions/checkout@v3
2626

27+
- name: Extract branch name
28+
shell: bash
29+
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
30+
id: extract_branch
31+
2732
- name: Install Node.js ${{ matrix.node-version }}
2833
uses: actions/setup-node@v1
2934
with:
@@ -64,3 +69,9 @@ jobs:
6469
with:
6570
token: ${{ secrets.CODECOV_TOKEN }}
6671
directory: ./coverage
72+
- if: ${{ matrix.node-version == '16.x' && matrix.os == 'ubuntu-latest' && steps.extract_branch.outputs.branch == 'main' }}
73+
name: Semantic Release
74+
uses: cycjimmy/semantic-release-action@v3
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
"console": "integratedTerminal"
1515
}
1616
]
17-
}
17+
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 vagusX
3+
Copyright (c) 2022 bundle-matters
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,123 @@
11
# Less Plugin Module Resolver
22

3+
![Github Action](https://github.com/bundle-matters/less-plugin-module-resolver/actions/workflows/ci.yml/badge.svg) [![codecov](https://codecov.io/gh/bundle-matters/less-plugin-module-resolver/branch/main/graph/badge.svg?token=ITYULU4YJ3)](https://codecov.io/gh/bundle-matters/less-plugin-module-resolver) [![Version](https://img.shields.io/npm/v/less-plugin-module-resolver.svg?sanitize=true)](https://www.npmjs.com/package/less-plugin-module-resolver) [![Downloads](https://img.shields.io/npm/dm/less-plugin-module-resolver.svg?sanitize=true)](https://npmcharts.com/compare/less-plugin-module-resolver?minimal=true) [![License](https://img.shields.io/npm/l/less-plugin-module-resolver.svg?sanitize=true)](https://www.npmjs.com/package/less-plugin-module-resolver)
4+
5+
> Inspired by [less-plugin-npm-import](https://github.com/less/less-plugin-npm-import) and [babel-plugin-module-resolver](https://github.com/tleunen/babel-plugin-module-resolver)
6+
7+
Adds the ability for less to set alias imports. Especially to handle usage like `~` in [webpack](https://webpack.js.org/loaders/less-loader/#imports) when using Rollup or other bundlers.
8+
9+
## Install
10+
11+
```shell
12+
# use npm
13+
npm install babel-plugin-module-resolver
14+
15+
# use yarn
16+
yarn add babel-plugin-module-resolver
17+
18+
# use pnpm
19+
pnpm install babel-plugin-module-resolver
20+
```
21+
322
## Usage
423

24+
```less
25+
@import (less) '~normalize.css';
26+
```
27+
28+
```js
29+
const less = require('less');
30+
const ModuleResolverPlugin = require('less-plugin-module-resolver');
31+
32+
less.render('input', {
33+
plugins: [
34+
new ModuleResolverPlugin({
35+
alias: {
36+
'~': '',
37+
},
38+
}),
39+
],
40+
});
41+
```
42+
43+
## Plugin Options
44+
45+
### **rootDir**
46+
47+
The directory to resolve less files. Default to `''`.
48+
49+
### **alias**
50+
51+
```js
52+
const less = require('less');
53+
const ModuleResolverPlugin = require('less-plugin-module-resolver');
54+
55+
less.render('input', {
56+
plugins: [
57+
new ModuleResolverPlugin({
58+
rootDir: path.resolve(__dirname, 'src'),
59+
alias: {
60+
$: (_, restPath) => `styles${restPath}`),
61+
'^@mixins$': 'styles/mixins/index.less',
62+
},
63+
}),
64+
],
65+
});
66+
```
67+
68+
When using the above configs:
69+
70+
```less
71+
# origin
72+
@import "@mixins";
73+
@import "$/variables/index.less";
74+
75+
# converted to
76+
@import "/User/me/project-foo/src/styles/mixins/index.less";
77+
@import "/User/me/project-foo/src/styles/variables/index.less";
78+
```
79+
80+
The alias config to resolve import less files. Alias key should be string including `regexp string`, corresponding replacer value should be string. You can use function replacer when the situation is more complicated.
81+
82+
**More detailed api about alias see below:**
83+
84+
#### **alias key**
85+
86+
Alias key should be a `normal string` or `regexp string`. Mind that regexp string will pass to `RegexpConstructor` and should be not enclosed between slashes but started with `^` or end with `$`.
87+
88+
##### More docs about `RegexpPatternString`
89+
90+
- [`RegexpPatternString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp)
91+
- [`RegExp#literal_notation_and_constructor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/RegExp#literal_notation_and_constructor)
92+
93+
Note that you can use `special replacement patterns` from `String.prototype.replace`, like `$1`, `$n`. See [String_Replace#specifying_a_string_as_a_parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter)
94+
595
```js
696
const less = require('less');
797
const ModuleResolverPlugin = require('less-plugin-module-resolver');
898

999
less.render('input', {
10-
plugins: [new ModuleResolverPlugin()],
100+
plugins: [
101+
new ModuleResolverPlugin({
102+
rootDir: path.resolve(__dirname, 'src'),
103+
alias: {
104+
'^@theme/(.+)': 'styles/theme/$1.less',
105+
},
106+
}),
107+
],
11108
});
12109
```
110+
111+
#### **alias value**
112+
113+
Alias value should be a string replacer or function replacer. The function replacer is similar to the 2rd argument/callback in `String.prototype.replace`.
114+
115+
```ts
116+
type StringReplacer = string;
117+
118+
type FunctionReplacer = (substring: string, ...args: any[]) => string;
119+
```
120+
121+
## License
122+
123+
MIT

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
},
1313
"repository": {
1414
"type": "git",
15-
"url": "git+https://github.com/vagusX/less-plugin-module-resolver.git"
15+
"url": "git+https://github.com/bundle-matters/less-plugin-module-resolver.git"
1616
},
1717
"keywords": [],
1818
"author": "",
19-
"license": "ISC",
19+
"license": "MIT",
2020
"bugs": {
21-
"url": "https://github.com/vagusX/less-plugin-module-resolver/issues"
21+
"url": "https://github.com/bundle-matters/less-plugin-module-resolver/issues"
2222
},
23-
"homepage": "https://github.com/vagusX/less-plugin-module-resolver#readme",
23+
"homepage": "https://github.com/bundle-matters/less-plugin-module-resolver#readme",
2424
"devDependencies": {
2525
"@less/test-data": "^4.1.0",
2626
"@types/less": "^3.0.3",
@@ -35,6 +35,7 @@
3535
"lint-staged": "^12.4.1",
3636
"normalize.css": "^8.0.1",
3737
"prettier": "^2.6.2",
38+
"semantic-release": "^19.0.2",
3839
"typescript": "^4.6.4",
3940
"vitest": "^0.10.2"
4041
},

0 commit comments

Comments
 (0)