5.3.3 • Published 10 months ago

node-sass-once-importer v5.3.3

Weekly downloads
366
License
MIT
Repository
github
Last release
10 months ago

node-sass-once-importer

Patreon Donate Build Status Coverage Status GitHub stars

Import files only once. If the same file is imported in multiple @import statements, this package will ignore subsequent imports of the same file.

Usage

const sass = require('node-sass');
const onceImporter = require('node-sass-once-importer');

sass.render({
  ...
  importer: onceImporter()
  ...
});
// Example:
@import 'style1.scss';
@import 'style1.scss';
@import 'style2.scss';
// Contents of style1.scss:
.selector1 { }
.selector2 { }

// Contents of style2.scss:
.selector3 { }
.selector4 { }

webpack

// webpack.config.js
const onceImporter = require('node-sass-once-importer');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
          },
          {
            loader: 'css-loader'
          },
          {
            loader: 'sass-loader',
            options: {
              sassOptions: {
                importer: onceImporter()
              }
            }
          }
        ]
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: 'style.css'
    })
  ]
}

CLI

node-sass --importer node_modules/node-sass-once-importer/dist/cli.js -o dist src/index.scss

Why is there no 1.x, 2.x, 3.x or 4.x version?

This module is maintained in one repository together with multiple other node-sass custom importers. The node-sass-magic-importer repository is using a monorepo approach with fixed versions for all packages. The projects maintained in the node-sass-magic-importer monorepo started out as separate repositories with separate versioning, so when they were integrated into the monorepo, the versions of all projects were raised to 5.0.0 and are in sync since then.

node-sass-magic-importer

This module is powered by node-sass-magic-importer.

About

Author

Markus Oberlehner
Website: https://markus.oberlehner.net
Twitter: https://twitter.com/MaOberlehner
PayPal.me: https://paypal.me/maoberlehner
Patreon: https://www.patreon.com/maoberlehner

License

MIT