{"library":"node-sass-package-importer","title":"node-sass Package Importer","description":"node-sass-package-importer is a custom importer for node-sass designed to streamline the process of importing Sass files from `node_modules` directories within your Sass code. It simplifies path management by allowing module imports using a `~` prefix, such as `@import '~bootstrap';`, eliminating the need for complex relative paths. The package currently maintains a stable version of 5.3.3 and is part of a larger `node-sass-magic-importer` monorepo. It offers flexible configuration options, including customizable `packageKeys` to define which entries in a `package.json` file should be considered for import resolution (e.g., 'sass', 'scss', 'main'), and a configurable `packagePrefix`. Key differentiators include its robust path resolving logic for both root modules and specific files within modules, support for multi-level `node_modules` directories (since v5.2.0), and the ability to glob import empty directories (since v5.1.0). Recent updates address TypeScript resolution and shared context issues in Webpack. While `node-sass` itself is in maintenance, this package provides crucial functionality for projects still relying on it, offering a consistent and manageable way to handle third-party Sass dependencies.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-sass-package-importer"],"cli":null},"imports":["const packageImporter = require('node-sass-package-importer');","import packageImporter from 'node-sass-package-importer';","import type { ImporterOptions } from 'node-sass-package-importer';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import * as sass from 'node-sass';\nimport packageImporter from 'node-sass-package-importer';\n\nconst scssContent = `\n@import '~bootstrap';\n@import '~bootstrap/scss/variables';\n\nbody {\n  background-color: lightgray;\n}\n`;\n\nsass.render({\n  data: scssContent,\n  importer: packageImporter(),\n  includePaths: [], // Add relevant include paths if needed\n  outputStyle: 'expanded'\n}, (error, result) => {\n  if (error) {\n    console.error('Sass compilation error:', error.message);\n    return;\n  }\n  console.log('Compiled CSS:\\n', result.css.toString());\n  // Example of using options:\n  const customOptionsImporter = packageImporter({\n    packagePrefix: '@',\n    packageKeys: ['style', 'sass', 'main']\n  });\n  console.log('Importer with custom options created.');\n});","lang":"typescript","description":"Demonstrates basic usage by importing Bootstrap from `node_modules` using the `~` prefix and rendering Sass content with `node-sass`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}