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

rollup-plugin-sass

v1.14.0

Published

Rollup Sass files.

Downloads

88,316

Readme

rollup-plugin-sass CI issues npm mit Coverage Status

Installation

npm install rollup-plugin-sass -D

Usage

// rollup.config.js
import sass from 'rollup-plugin-sass';

export default {
  input: 'index.js',
  output: {
    file: 'bundle.js',
    format: 'cjs',
  },
  plugins: [sass()],
};

rollup.config.ts

Add allowSyntheticDefaultImports, or esModuleInterop (enables allowSyntheticDefaultImports), to tsconfig.json:

{
  "compilerOptions": {
    "esModuleInterOp": true
  }
}

Reference: (https://www.typescriptlang.org/tsconfig#esModuleInterop)

Write rollup.config.ts:

// rollup.config.ts
import sass from 'rollup-plugin-sass';

// ...

Profit.

Options

output

  • Type: Boolean|String|Function (default: false)
sass({
  // Default behaviour disable output
  output: false,

  // Write all styles to the bundle destination where .js is replaced by .css
  output: true,

  // Filename to write all styles
  output: 'bundle.css',

  // Callback that will be called ongenerate with two arguments:
  // - styles: the concatenated styles in order of imported
  // - styleNodes: an array of style objects:
  //  [
  //    { id: './style1.scss', content: 'body { color: red };' },
  //    { id: './style2.scss', content: 'body { color: green };' }
  //  ]
  output(styles, styleNodes) {
    writeFileSync('bundle.css', styles);
  },
});

insert

  • Type: Boolean (default: false)

If you specify true, the plugin will insert compiled CSS into <head/> tag, via utility function that it will output in your build bundle.

sass({
  insert: true,
});

processor

  • Type: Function

If you specify a function as processor which will be called with compiled css before generate phase.

import autoprefixer from 'autoprefixer';
import postcss from 'postcss';

sass({
  // Processor will be called with two arguments:
  // - style: the compiled css
  // - id: import id
  processor: (css) =>
    postcss([autoprefixer])
      .process(css)
      .then((result) => result.css),
});

The processor also support object result. Reverse css filLed for stylesheet, the rest of the properties can be customized.

sass({
  processor(code) {
    return {
      css: '.body {}',
      foo: 'foo',
      bar: 'bar',
    };
  },
});

Otherwise, you could do:

import style, { foo, bar } from 'stylesheet';

Exporting sass variable to *.js

Example showing how to use icss-utils to extract resulting sass vars to your *.js bundle:

const config = {
  input: 'test/fixtures/processor-promise/with-icss-exports.js',
  plugins: [
    sass({
      processor: (css) =>
        new Promise((resolve, reject) => {
          const pcssRootNodeRslt = postcss.parse(css),
            extractedIcss = extractICSS(pcssRootNodeRslt, true),
            cleanedCss = pcssRootNodeRslt.toString(),
            out = Object.assign({}, extractedIcss.icssExports, {
              css: cleanedCss,
            });
          // console.table(extractedIcss);
          // console.log(out);
          resolve(out);
        }),
      options: sassOptions,
    }),
  ],
};

See the Input file for example on how to access the exported vars.

runtime

  • Type: Object (default: sass)

If you specify an object, it will be used instead of sass. You can use this to pass a different sass compiler (for example the node-sass npm package).

options

  • Type: Object

Options for sass or your own runtime sass compiler.

If you specify data, the plugin will treat as prepend sass string. Since you can inject variables during sass compilation with node.

sass({
  options: {
    data: '$color: #000;',
  },
});

include

  • Type: string | string[]
  • Default: ['**/*.sass', '**/*.scss']

Glob of sass/css files to be targeted.

sass({
  include: ['**/*.css', '**/*.sass', '**/*.scss'],
});

exclude

  • Type: string | string[];
  • Default: 'node_modules/**'

Globs to exclude from processing.

sass({
  exclude: 'node_modules/**',
});

License

MIT elycruz, BinRui.Guan