@advdominion/lightningcss-loader
This commit is contained in:
53
packages/lightningcss-loader/README.md
Normal file
53
packages/lightningcss-loader/README.md
Normal 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,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
22
packages/lightningcss-loader/index.js
Normal file
22
packages/lightningcss-loader/index.js
Normal 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;
|
||||
14
packages/lightningcss-loader/package.json
Normal file
14
packages/lightningcss-loader/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user