@thedanbob/esbuild-plugin-sass 1.1.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/dist/index.d.ts +2 -3
- package/dist/index.js +22 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,8 +10,8 @@ npm install --save-dev esbuild @thedanbob/esbuild-plugin-sass
|
|
|
10
10
|
|
|
11
11
|
## How to use
|
|
12
12
|
|
|
13
|
+
`esbuild.config.js`:
|
|
13
14
|
```js
|
|
14
|
-
// esbuild.config.js
|
|
15
15
|
import { build } from "esbuild"
|
|
16
16
|
import sassPlugin from "@thedanbob/esbuild-plugin-sass"
|
|
17
17
|
|
|
@@ -23,6 +23,13 @@ await build({
|
|
|
23
23
|
});
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
`app.scss`:
|
|
27
|
+
```scss
|
|
28
|
+
/* Prepend with ~ to import from node_modules */
|
|
29
|
+
@import "~bootstrap/scss/bootstrap"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Run:
|
|
26
33
|
```bash
|
|
27
34
|
node esbuild.config.js
|
|
28
35
|
```
|
|
@@ -47,12 +54,6 @@ Default: `[]`
|
|
|
47
54
|
|
|
48
55
|
Array of [deprecations](https://sass-lang.com/documentation/js-api/interfaces/options/#silenceDeprecations) to silence.
|
|
49
56
|
|
|
50
|
-
### `importers`
|
|
51
|
-
Type: `(NodePackageImporter | Importer<sync> | FileImporter<sync>)[]`<br>
|
|
52
|
-
Default: `[]`
|
|
53
|
-
|
|
54
|
-
Array of [importers](https://sass-lang.com/documentation/js-api/interfaces/options/#importers) passed to the Sass compiler.
|
|
55
|
-
|
|
56
57
|
### `transform`
|
|
57
58
|
Type: `(css: string, resolveDir: string, filePath: string) => string | Promise<string>`<br>
|
|
58
59
|
Default: `undefined`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Plugin } from "esbuild";
|
|
2
|
-
import {
|
|
2
|
+
import { DeprecationOrId } from "sass";
|
|
3
3
|
export interface PluginOptions {
|
|
4
4
|
filter?: RegExp;
|
|
5
|
-
importers?: Options<"sync">["importers"];
|
|
6
5
|
quietDeps?: boolean;
|
|
7
6
|
silenceDeprecations?: DeprecationOrId[];
|
|
8
7
|
transform?: (css: string, resolveDir: string, filePath: string) => string | Promise<string>;
|
|
9
8
|
}
|
|
10
|
-
declare const _default: ({ filter, quietDeps, silenceDeprecations,
|
|
9
|
+
declare const _default: ({ filter, quietDeps, silenceDeprecations, transform }?: PluginOptions) => Plugin;
|
|
11
10
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { compile } from "sass";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
4
|
+
const importer = {
|
|
5
|
+
findFileUrl: (url) => {
|
|
6
|
+
if (!url.startsWith("~"))
|
|
7
|
+
return null;
|
|
8
|
+
try {
|
|
9
|
+
// import.meta.resolve searches for an index file by default, which isn't guaranteed to exist.
|
|
10
|
+
// Instead, we attempt to resolve <package>/package.json
|
|
11
|
+
const file = url.replace(/^~(.+?)\/.+/, "$1/package.json");
|
|
12
|
+
return new URL(url.substring(1), import.meta.resolve(file).replace(/(?<=node_modules\/).+/, ""));
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export default ({ filter = /.(s[ac]ss|css)$/, quietDeps = false, silenceDeprecations = [], transform = undefined } = {}) => ({
|
|
5
20
|
name: "sass",
|
|
6
21
|
setup: async ({ initialOptions, onLoad }) => {
|
|
7
22
|
onLoad({ filter }, async ({ path }) => {
|
|
@@ -35,24 +50,22 @@ export default ({ filter = /.(s[ac]ss|css)$/, quietDeps = false, silenceDeprecat
|
|
|
35
50
|
logger,
|
|
36
51
|
quietDeps,
|
|
37
52
|
silenceDeprecations,
|
|
38
|
-
importers
|
|
53
|
+
importers: [importer]
|
|
39
54
|
});
|
|
40
|
-
let
|
|
55
|
+
let contents = css.toString();
|
|
41
56
|
if (sourceMap) {
|
|
42
57
|
const data = Buffer.from(JSON.stringify(sourceMap), "utf-8").toString("base64");
|
|
43
|
-
|
|
44
|
-
cssText += "\n" + sm;
|
|
58
|
+
contents += `\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${data} */`;
|
|
45
59
|
}
|
|
46
60
|
if (transform) {
|
|
47
|
-
|
|
61
|
+
contents = await transform(contents, resolveDir, path);
|
|
48
62
|
}
|
|
49
|
-
const watchFiles = [path, ...loadedUrls.map(u => fileURLToPath(u))];
|
|
50
63
|
return {
|
|
51
|
-
contents: cssText,
|
|
52
64
|
loader: "css",
|
|
65
|
+
contents,
|
|
53
66
|
resolveDir,
|
|
54
67
|
warnings,
|
|
55
|
-
watchFiles
|
|
68
|
+
watchFiles: [path, ...loadedUrls.map(u => fileURLToPath(u))]
|
|
56
69
|
};
|
|
57
70
|
});
|
|
58
71
|
}
|