What is detective-sass?
The detective-sass npm package is designed to analyze SASS (.scss) files to find and extract import statements. This can be particularly useful in build tools and bundlers where understanding dependencies between stylesheets is necessary for tasks like concatenation, minification, or modular builds. It parses the content of SASS files and returns an array of strings representing the paths of files that are imported.
What are detective-sass's main functionalities?
Extract import paths from a SASS file
This feature allows you to pass in the content of a SASS file as a string to the detective function, which then returns an array of the import paths found within that file. This is useful for tracking dependencies in SASS projects.
const detective = require('detective-sass');
const content = `$importedVar: #123;
@import 'another-file';
body { color: $importedVar; }`;
const imports = detective(content);
console.log(imports); // ['another-file']
Other packages similar to detective-sass
postcss-import
Similar to detective-sass, postcss-import is used to process import statements in CSS files. While detective-sass focuses on SASS files, postcss-import is more versatile, working with CSS files and supporting features like glob, path resolving, and inline imports. It's part of the PostCSS ecosystem, which allows for a wide range of plugins to further process the CSS.
node-sass-glob-importer
This package provides a custom importer for node-sass, enabling glob-based imports in SASS files. While detective-sass extracts import paths for analysis or bundling, node-sass-glob-importer enhances the import capabilities of SASS itself, allowing for more flexible and powerful stylesheet organization.
detective-sass
Find the dependencies of a sass/scss file
npm install --save detective-sass
It's the SASS counterpart to detective, detective-amd, and detective-es6.
Usage
var detective = require('detective-sass');
var content = fs.readFileSync('styles.scss', 'utf8');
var dependencies = detective(content);
You can also supply an optional set of configuration options as the second argument to detective
:
var dependencies = detective(content, {
syntax: 'sass'
});
Options you can specify:
syntax
: The syntax of the file. Instructs the parser which language to expect.
Related
Check out node-sass-lookup if you want to map a sass/scss dependency to a file on your filesystem.
License
MIT