lightningcss-loader/index.js

21 lines
726 B
JavaScript
Raw Permalink Normal View History

2024-05-28 23:25:49 +03:00
export default function (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()));
}