npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jgoz/esbuild-plugin-sass

v2.0.8

Published

Sass plugin for esbuild

Downloads

1,824

Readme

@jgoz/esbuild-plugin-sass

An esbuild plugin for loading Sass/SCSS files using the CSS content type.

This plugin was forked from esbuild-sass-plugin to facilitate migrations from Webpack. Libraries that rely on sass-loader's import resolution logic should mostly just work.

Features

  • Uses same module resolution algorithm as Webpack's sass-loader, including ~ as a prefix for node_modules in imports
  • Provides a separate transform stage on the resulting CSS that may be used to apply PostCSS/Autoprefixer processing (mimics chained loaders in Webpack)
  • Supports the same options as Dart Sass

Install

$ npm i @jgoz/esbuild-plugin-sass

Usage

Add it to your esbuild plugins:

const esbuild = require('esbuild');
const { sassPlugin } = require('@jgoz/esbuild-plugin-sass');

await esbuild.build({
  // ...
  plugins: [sassPlugin()],
});

This will produce a separate CSS output file for each entry point you define containing the transpiled Sass output.

Usage with PostCSS/Autoprefixer

The transform option can be used to process CSS output using PostCSS or any other utility.

const esbuild = require('esbuild');
const { sassPlugin } = require('@jgoz/esbuild-plugin-sass');
const autoprefixer = require('autoprefixer');
const presetEnv = require('postcss-preset-env');
const postcss = require('postcss');

const processor = postcss([autoprefixer, presetEnv()]);

await esbuild.build({
  // ...
  plugins: [
    sassPlugin({
      async transform(source, resolveDir) {
        const { css } = await processor.process(source, { from: resolveDir });
        return css;
      },
    }),
  ],
});

API

function sassPlugin(options?: SassPluginOptions): Plugin

Plugin options:

| Name | Type | Default | Description | | ---- | ---- | ------- | ----------- | | alias | Record<string, string \| string[]> | - | Import aliases to use when resolving imports from within sass files.These will not be used when esbuild resolves imports from other module types. | | basedir | string | process.cwd() | Base directory to use when resolving the sass implementation. | | functions | Record<string, LegacySyncFunction> | - | Holds a collection of custom functions that may be invoked by the sass files being compiled. | | importer | LegacySyncImporter \| LegacySyncImporter[] | - | Resolves @import directives between sass files.This is not used when esbuild resolves imports from other module types, e.g., when importing from JS/TS files or when defining a Sass file as an entry point.If left undefined, a default importer will be used that closely mimics webpack's sass-loader resolution algorithm, which itself closely mimic's the default resolution algorithm of dart-sass.If you want to extend the import algorithm while keeping the default, you can import it like so:Exampleimport { createSassImporter } from '@jgoz/esbuild-plugin-sass';const defaultImporter = createSassImporter( [], // includePaths {}, // aliases);sassPlugin({ importer: [myImporter, defaultImporter]}) | | includePaths | string[] | [] | An array of paths that should be looked in to attempt to resolve your @import declarations. When using data, it is recommended that you use this. | | indentType | "space" \| "tab" | 'space' | Used to determine whether to use space or tab character for indentation. | | indentWidth | number | 2 | Used to determine the number of spaces or tabs to be used for indentation. | | indentedSyntax | boolean | false | Enable Sass Indented Syntax for parsing the data string or file. | | linefeed | "cr" \| "crlf" \| "lf" \| "lfcr" | 'lf' | Used to determine which sequence to use for line breaks. | | outputStyle | "compressed" \| "expanded" | 'expanded' | Determines the output format of the final CSS style. | | sourceMap | string \| boolean | - | Enables the outputting of a source map. | | sourceMapContents | boolean | false | Includes the contents in the source map information. | | sourceMapEmbed | boolean | false | Embeds the source map as a data URI. | | sourceMapRoot | string | - | The value will be emitted as sourceRoot in the source map information. | | transform | (css: string, resolveDir: string) => string \| Promise<string> | - | A function that will post-process the css output before wrapping it in a module.This might be useful for, e.g., processing CSS output with PostCSS/autoprefixer.Exampleconst postCSS = require("postcss")([ require("autoprefixer"), require("postcss-preset-env")({ stage:0 })]);sassPlugin({ async transform(source, resolveDir) { const { css } = await postCSS.process( source, { from: resolveDir } ); return css; }}) |