Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: 🤖 bump dependencies and update readme #119

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.11.0
node-version: 20.11.1
cache: 'yarn'

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.11.0
node-version: 20.11.1
cache: 'yarn'

- name: Install dependencies
Expand Down
672 changes: 336 additions & 336 deletions .yarn/releases/yarn-4.0.2.cjs → .yarn/releases/yarn-4.1.1.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.0.2.cjs
yarnPath: .yarn/releases/yarn-4.1.1.cjs
41 changes: 8 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@

# esbuild-plugin-less

[esbuild](https://github.com/evanw/esbuild) plugin for less files
[esbuild](https://github.com/evanw/esbuild) plugin for less files.

## Install
## Installation

```
```sh
yarn add esbuild-plugin-less -D
```

## Usage

### Simple example

You can see the example [here](./example).

```ts
Expand All @@ -32,44 +30,21 @@ build({
entryPoints: [path.resolve(__dirname, 'index.ts')],
bundle: true,
outdir: path.resolve(__dirname, 'output'),
plugins: [lessLoader()],
plugins: [lessLoader()], // Just plug in
loader: {
'.ts': 'ts',
},
});
```

### Watch mode

More information about watch mode [here](https://esbuild.github.io/api/#watch).
## Configuration

```ts
import { build } from 'esbuild';
import { lessLoader } from 'esbuild-plugin-less';

build({
watch: true, // enable watch mode
entryPoints: [path.resolve(__dirname, 'index.ts')],
bundle: true,
outdir: path.resolve(__dirname, 'output'),
plugins: [lessLoader()],
loader: {
'.ts': 'ts',
},
});
```

## Options

`lessLoader` accepts all valid options from less.js. You can find a complete list of options [here](http://lesscss.org/usage/#less-options).

`LoaderOptions` loader options, support custom [filter](https://esbuild.github.io/plugins/#filters)
```
{
filter: /\.less$/,
}
lessLoader(lessOptions: Less.Options = {}, loaderOptions: LoaderOptions = {})
```

- `options` — Accepts all valid options from less.js. You can find a complete list of options [here](http://lesscss.org/usage/#less-options).
- `loaderOptions` — Options for the loader. Supports custom esbuild [filter](https://esbuild.github.io/plugins/#filters).

## License

Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@
"@semantic-release/changelog": "6.0.3",
"@semantic-release/commit-analyzer": "11.1.0",
"@semantic-release/github": "9.2.6",
"@semantic-release/npm": "11.0.2",
"@semantic-release/npm": "11.0.3",
"@semantic-release/release-notes-generator": "12.1.0",
"@types/node": "^20.11.9",
"@vitest/coverage-v8": "^1.2.2",
"@types/node": "20.11.26",
"@vitest/coverage-v8": "1.3.1",
"cz-conventional-changelog": "3.3.0",
"esbuild": "^0.20.0",
"esbuild": "0.20.1",
"git-cz": "4.9.0",
"husky": "^9.0.6",
"lint-staged": "15.2.0",
"prettier": "3.2.4",
"semantic-release": "23.0.0",
"tsx": "4.7.0",
"typescript": "5.3.3",
"vite": "^5.0.12",
"vitest": "^1.2.2"
"husky": "9.0.11",
"lint-staged": "15.2.2",
"prettier": "3.2.5",
"semantic-release": "23.0.2",
"tsx": "4.7.1",
"typescript": "5.4.2",
"vite": "5.1.6",
"vitest": "1.3.1"
},
"peerDependencies": {
"esbuild": "^0.14.x || ^0.15.0 || ^0.16.0 || ^0.17.0 || ^0.18.0 || ^0.19.0 || ^0.20.0"
Expand All @@ -75,8 +75,8 @@
"less"
],
"volta": {
"node": "20.11.0",
"yarn": "1.22.21"
"node": "20.11.1",
"yarn": "1.22.22"
},
"husky": {
"hooks": {
Expand All @@ -93,5 +93,5 @@
"path": "./node_modules/cz-conventional-changelog"
}
},
"packageManager": "yarn@4.0.2"
"packageManager": "yarn@4.1.1"
}
42 changes: 21 additions & 21 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ function getOutputFilename(format: Format) {
}
}

function createBuild() {
formats.map((format) => {
async function createBuild() {
for (const format of formats) {
const outputFilename = getOutputFilename(format);

build({
entryPoints: [path.resolve(__dirname, '..', 'src', 'index.ts')],
bundle: true,
minify: true,
platform: 'node',
loader: {
'.ts': 'ts',
},
external: ['less', 'path', 'fs'],
outfile: path.resolve(__dirname, '..', 'build', outputFilename),
format,
})
.then(() => {
console.info(`— ${outputFilename} was built`);
})
.catch((e) => {
console.info(`🚨 ${outputFilename} build error:`);
console.error(e);
try {
await build({
entryPoints: [path.resolve(__dirname, '..', 'src', 'index.ts')],
bundle: true,
minify: true,
platform: 'node',
loader: {
'.ts': 'ts',
},
external: ['less', 'path', 'fs'],
outfile: path.resolve(__dirname, '..', 'build', outputFilename),
format,
});
});

console.info(`— ${outputFilename} was built`);
} catch (e) {
console.info(`🚨 ${outputFilename} build error:`);
console.error(e);
}
}
}

createBuild();
16 changes: 9 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import type { Loader, Plugin } from 'esbuild';
import path from 'path';
import { promises as fs } from 'fs';
import path from 'path';
import less from 'less';
import { convertLessError, getLessImports } from './less-utils';

export interface LoaderOptions {
/* custom filter */
/* Custom filter */
filter?: RegExp;
}

/** Less-loader for esbuild */
export function lessLoader(options: Less.Options = {}, loaderOptions: LoaderOptions = {}): Plugin {
/**
* `esbuild` loader for `.less` files
*/
export function lessLoader(lessOptions: Less.Options = {}, loaderOptions: LoaderOptions = {}): Plugin {
return {
name: 'less-loader',
setup: (build) => {
Expand All @@ -28,7 +30,7 @@ export function lessLoader(options: Less.Options = {}, loaderOptions: LoaderOpti

return {
path: filePath,
watchFiles: [filePath, ...getLessImports(filePath, options.paths || [])],
watchFiles: [filePath, ...getLessImports(filePath, lessOptions.paths || [])],
};
});

Expand All @@ -43,8 +45,8 @@ export function lessLoader(options: Less.Options = {}, loaderOptions: LoaderOpti
const opts: Less.Options & { relativeUrls: boolean } = {
filename: args.path,
relativeUrls: true,
...options,
paths: [...(options.paths || []), dir],
...lessOptions,
paths: [...(lessOptions.paths || []), dir],
};

try {
Expand Down
Loading