esbuild-sass-plugin
Advanced tools
Comparing version 1.5.3 to 1.5.4
@@ -0,0 +0,0 @@ import { SassPluginOptions } from "./index"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { OnLoadResult } from "esbuild"; |
@@ -0,0 +0,0 @@ "use strict"; |
import { Plugin } from "esbuild"; | ||
import { SassPluginOptions } from "./index"; | ||
export declare function sassPlugin(options?: SassPluginOptions): Plugin; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { SassPluginOptions, Type } from "./index"; |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "esbuild-sass-plugin", | ||
"version": "1.5.3", | ||
"version": "1.5.4", | ||
"description": "esbuild plugin for sass/scss files supporting both css loader and css result import (lit-element)", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -88,2 +88,3 @@ ![logo created with https://cooltext.com](https://images.cooltext.com/5500652.png) | ||
|exclude|regex|undefined| | ||
|importMapper|function|undefined| | ||
@@ -127,2 +128,30 @@ | ||
### ImportMapper Option | ||
Function to customize re-map import path, both `import` in ts code and `@import` | ||
in scss coverd. | ||
You can use this option to re-map import paths like tsconfig's `paths` option. | ||
e.g. | ||
```json | ||
//tsconfig | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@img/*": ["./assets/images/*"] //map image files | ||
} | ||
} | ||
} | ||
``` | ||
Now you can resolve these paths with `importMapper` | ||
```javascript | ||
await esbuild.build({ | ||
... | ||
plugins: [sassPlugin({ | ||
importMapper: (path)=> | ||
path.replace(/^@img\//,"./assets/images/") | ||
})] | ||
}) | ||
``` | ||
### Transform Option | ||
@@ -129,0 +158,0 @@ ```typescript |
import {SassPluginOptions} from "./index"; | ||
import resolve from "resolve"; | ||
export function createSassImporter({basedir = process.cwd()}: SassPluginOptions) { | ||
export function createSassImporter({basedir = process.cwd(), importMapper }: SassPluginOptions) { | ||
@@ -12,2 +12,5 @@ const opts = {basedir, extensions: [".scss", ".sass", ".css"]}; | ||
} | ||
if (importMapper) { | ||
url = importMapper(url) | ||
} | ||
try { | ||
@@ -14,0 +17,0 @@ return {file: resolve.sync(url, opts)}; |
@@ -7,2 +7,7 @@ import {OnLoadResult} from "esbuild"; | ||
export type SassPluginOptions = { | ||
/** | ||
* Function to transform import path. Not just paths by @import | ||
* directive, but also paths imported by ts code. | ||
*/ | ||
importMapper?:(url: string) => string | ||
@@ -9,0 +14,0 @@ /** |
@@ -67,2 +67,8 @@ import {OnLoadArgs, OnLoadResult, OnResolveArgs, Plugin} from "esbuild"; | ||
} | ||
const mapper = options.importMapper | ||
if(mapper) { | ||
path = mapper(path) | ||
} | ||
const paths = options.includePaths ? [resolveDir, ...options.includePaths] : [resolveDir]; | ||
@@ -69,0 +75,0 @@ return require.resolve(path, {paths}); |
@@ -0,0 +0,0 @@ import {SassPluginOptions, Type} from "./index"; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
757
264
49528
1