@thedanbob/esbuild-plugin-sass 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ @thedanbob/esbuild-plugin-sass
2
+
3
+ MIT License
4
+
5
+ Copyright (c) 2026 Dan Arnfield
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # @thedanbob/esbuild-plugin-sass
2
+
3
+ Sass plugin for [esbuild](https://esbuild.github.io/). This is basically a heavily stripped down version of [esbuild-sass-plugin](https://github.com/glromeo/esbuild-sass-plugin), you should probably just use that one.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install --save-dev esbuild @thedanbob/esbuild-plugin-sass
9
+ ```
10
+
11
+ ## How to use
12
+
13
+ ```js
14
+ // esbuild.config.js
15
+ import { build } from "esbuild"
16
+ import sassPlugin from "@thedanbob/esbuild-plugin-sass"
17
+
18
+ await build({
19
+ // ...
20
+ plugins: [
21
+ sassPlugin({ /* config */ })
22
+ ]
23
+ });
24
+ ```
25
+
26
+ ```bash
27
+ node esbuild.config.js
28
+ ```
29
+
30
+ ## Config
31
+
32
+ ### `filter`
33
+
34
+ Type: `RegExp`<br>
35
+ Default: `/.(s[ac]ss|css)$/`
36
+
37
+ Esbuild load filter (go syntax).
38
+
39
+ ### `importers`
40
+ Type: `(NodePackageImporter | Importer<sync> | FileImporter<sync>)[]`<br>
41
+ Default: `[]`
42
+
43
+ Array of [importers](https://sass-lang.com/documentation/js-api/interfaces/options/#importers) passed to the Sass compiler.
44
+
45
+ ### `transform`
46
+ Type: `(css: string, resolveDir: string, filePath: string) => string | Promise<string>`<br>
47
+ Default: `undefined`
48
+
49
+ Function that post-processes the CSS compiled by Sass before returning it to esbuild.
50
+
51
+ ## License
52
+
53
+ MIT
@@ -0,0 +1,9 @@
1
+ import { Plugin } from "esbuild";
2
+ import { Options } from "sass";
3
+ export interface PluginOptions {
4
+ filter?: RegExp;
5
+ importers?: Options<"sync">["importers"];
6
+ transform?: (css: string, resolveDir: string, filePath: string) => string | Promise<string>;
7
+ }
8
+ declare const _default: ({ filter, importers, transform }?: PluginOptions) => Plugin;
9
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,57 @@
1
+ import { compile } from "sass";
2
+ import { dirname } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ export default ({ filter = /.(s[ac]ss|css)$/, importers = [], transform = undefined } = {}) => ({
5
+ name: "sass",
6
+ setup: async ({ initialOptions, onLoad }) => {
7
+ onLoad({ filter }, async ({ path }) => {
8
+ const resolveDir = dirname(path);
9
+ const warnings = [];
10
+ const logger = {
11
+ warn: function (message, opts) {
12
+ if (!opts.span) {
13
+ warnings.push({ text: `sass warning: ${message}` });
14
+ }
15
+ else {
16
+ warnings.push({
17
+ text: message,
18
+ location: {
19
+ file: opts.span.url?.pathname ?? path,
20
+ line: opts.span.start.line,
21
+ column: opts.span.start.column,
22
+ lineText: opts.span.text
23
+ },
24
+ detail: {
25
+ deprecation: opts.deprecation,
26
+ stack: opts.stack
27
+ }
28
+ });
29
+ }
30
+ }
31
+ };
32
+ const { css, loadedUrls, sourceMap } = compile(path, {
33
+ sourceMap: !!initialOptions.sourcemap,
34
+ sourceMapIncludeSources: true,
35
+ logger,
36
+ importers
37
+ });
38
+ let cssText = css.toString();
39
+ if (sourceMap) {
40
+ const data = Buffer.from(JSON.stringify(sourceMap), "utf-8").toString("base64");
41
+ const sm = `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${data} */`;
42
+ cssText += "\n" + sm;
43
+ }
44
+ if (transform) {
45
+ cssText = await transform(cssText, resolveDir, path);
46
+ }
47
+ const watchFiles = [path, ...loadedUrls.map(u => fileURLToPath(u))];
48
+ return {
49
+ contents: cssText,
50
+ loader: "css",
51
+ resolveDir,
52
+ warnings,
53
+ watchFiles
54
+ };
55
+ });
56
+ }
57
+ });
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@thedanbob/esbuild-plugin-sass",
3
+ "author": "Dan Arnfield <npm@thedanbob.com>",
4
+ "version": "1.0.0",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "types": "./dist/types/index.d.ts",
14
+ "scripts": {
15
+ "clean": "rm -rf ./dist",
16
+ "build": "tsc --project tsconfig.json",
17
+ "lint": "eslint src/** --max-warnings=0 && tsc --noEmit"
18
+ },
19
+ "peerDependencies": {
20
+ "esbuild": "^0.27.3"
21
+ },
22
+ "dependencies": {
23
+ "sass": "^1.97.3"
24
+ },
25
+ "devDependencies": {
26
+ "@eslint/js": "^9.0.0",
27
+ "@types/node": "^25.2.2",
28
+ "esbuild": "^0.27.3",
29
+ "eslint": "^9",
30
+ "sass": "^1.97.3",
31
+ "typescript-eslint": "^8.20.0",
32
+ "typescript": "^5.9.3"
33
+ },
34
+ "engines": {
35
+ "node": ">=22"
36
+ },
37
+ "keywords": [
38
+ "esbuild",
39
+ "plugin",
40
+ "sass"
41
+ ],
42
+ "license": "MIT"
43
+ }