esbuild-sass-glob

raw JSON →
1.0.8 verified Fri May 01 auth: no javascript

Adds glob pattern support to @import statements in SCSS/SASS files when using esbuild-sass-plugin. Version 1.0.8 allows using wildcards like `@import './**/*.scss'` with the plugin's precompile hook. Lightweight alternative to webpack glob loaders, focused solely on esbuild integration. Currently stable with no active development; relies on esbuild-sass-plugin (v2+) as a peer dependency.

error Error: Cannot find module 'esbuild-sass-glob'
cause The package is not installed or is not in node_modules.
fix
Run 'npm install esbuild-sass-glob' in your project.
error TypeError: sassGlob is not a function
cause Incorrect import style; likely used import { sassGlob } instead of default import or used require without .default.
fix
Use 'import sassGlob from 'esbuild-sass-glob'' or 'const sassGlob = require('esbuild-sass-glob').default'
error Error: The option 'precompile' is not available in sassPlugin
cause Using an older version of esbuild-sass-plugin (v1) that doesn't have precompile.
fix
Update esbuild-sass-plugin to v2 or later: 'npm install esbuild-sass-plugin@latest'
gotcha Glob patterns are resolved relative to the importing file's directory, not the project root. Use relative paths like './**/*.scss'.
fix Ensure glob paths begin with './' or '../' to reference relative to the file.
gotcha Only @import statements are processed; @use and @forward are not supported. Migration to Sass's new module system will break globs.
fix Continue using @import or switch to a different glob tool supporting @use.
deprecated Sass itself deprecated @import in favor of @use/@forward. This library only supports the deprecated syntax.
fix Consider migrating to Dart Sass with @use and a different glob approach.
gotcha If esbuild-sass-plugin is not installed or the precompile option is not provided, glob expansion will not work and errors may be silent.
fix Ensure esbuild-sass-plugin is installed and precompile is set correctly.
npm install esbuild-sass-glob
yarn add esbuild-sass-glob
pnpm add esbuild-sass-glob

Configure esbuild with sass plugin and glob support for SCSS imports using precompile hook.

import sassPlugin from 'esbuild-sass-plugin';
import sassGlob from 'esbuild-sass-glob';
import esbuild from 'esbuild';

esbuild.build({
  entryPoints: ['src/index.scss'],
  outfile: 'dist/bundle.css',
  plugins: [
    sassPlugin({
      precompile: (source, pathname) => sassGlob(source, pathname),
    }),
  ],
}).catch(() => process.exit(1));