@advdominion/lightningcss-loader

This commit is contained in:
2026-01-21 15:13:48 +04:00
parent 9131e220d2
commit ca88f622d1
4 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
# lightningcss-loader
[Lightning CSS](https://lightningcss.dev) loader for [Webpack](https://webpack.js.org)
## Usage
```js
import { transform } from 'lightningcss';
return {
...,
rules: [
{
test: /\.css$/,
use: [
{
loader: '@advdominion/lightningcss-loader',
options: {
implementation: transform,
},
},
],
},
],
};
```
### Passing options to Lightning CSS
```js
import { transform } from 'lightningcss';
return {
...,
rules: [
{
test: /\.css$/,
use: [
{
loader: '@advdominion/lightningcss-loader',
options: {
implementation: transform,
drafts: {
customMedia: true,
},
minify: false,
},
},
],
},
],
};
```

View File

@@ -0,0 +1,22 @@
const lightningcssLoader = (source, sourceMap) => {
const { implementation, ...options } = this.getOptions();
const callback = this.async();
if (typeof implementation !== 'function') {
throw new TypeError(
`[lightningcss-loader]: The "implementation" option is required and must provide "transform" function of the LightningCSS`,
);
}
const { code, map } = implementation({
filename: this.resourcePath,
code: Buffer.from(source),
sourceMap: this.sourceMap,
inputSourceMap: this.sourceMap && sourceMap ? JSON.stringify(sourceMap) : undefined,
...options,
});
callback(undefined, code.toString(), map && JSON.parse(map.toString()));
}
export default lightningcssLoader;

View File

@@ -0,0 +1,14 @@
{
"name": "@advdominion/lightningcss-loader",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://gitea.optiweb.ru/public/frontend.git"
},
"license": "MIT",
"publishConfig": {
"access": "public"
}
}