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

grunt-sass-directory-import

v0.1.4

Published

Include all the .scss files in a directory by including a dynamically maintained _*.scss file.

Downloads

855

Readme

grunt-sass-directory-import

Include all the _.scss files in a directory by including a dynamically maintained _*.scss file.

In Sass, it's impossible to important a directory full of _*.scss files (partials) automatically, and this answer from Stack Overflow probably explains why.

But for me, source order isn't important: I like to have directories full of partials that should be independent from each other, especially when I'm using a system like SMACSS, where I have things like directories full of modules, mixins, functions, etc.

Using this task, you just add an _all.scss to any directory where you'd like to be able to import everything. This task will write all the necessary @imports to it so that when you @import that _all.scss partial, you will import all other partials in the directory.

Note: this plugin does not include non-partials, or *.scss files not prefixed by an underscore. Those get turned into regular .css files, and don't make sense to me as something that should be automatically swept up in other includes.

You can read more in my original blog post.

Note: If you're not Grunt-oriented, there's actually a more full-featured alternative available as a ruby gem: Chris Eppstein's Sass Globbing.

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-sass-directory-import --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-sass-directory-import');

The "sass_directory_import" task

Overview

In your project's Gruntfile, add a section named sass_directory_import to the data object passed into grunt.initConfig().

Important: When you execute your tasks, this task needs to be executed before your Compass task, or whatever task compiles your *.scss files.

grunt.initConfig({
  sass_directory_import: {
    your_target: {
      // Target-specific file lists and/or options go here.
      files: {
        // The file pattern to add @imports to.
        // The name of the file is arbitrary - I like "all".
        src: ['path/to/scss/files/**/_all.scss']
    },
  },
})

Options

options.quotes

Type: String Default value: double

This plugin writes @import statements, which use quotes. By default, they're double quotes, but maybe you have a linter on your Sass (yay!) and want to use single quotes. Set this to 'single'.

options.quiet

Type: Boolean Default value: False

By default, this plugin outputs information about the files it finds to your Grunt output.

Set to true to quiet this.

Usage Examples

Default Options

Find any _all.scss directories in your scss folder and subfolders and add @imports to them to any partials (_*.scss files) in that directory.

grunt.initConfig({
  sass_directory_import: {
    files: {
      src: ['src/scss/**/_all.scss']
    },
  },
})

Custom Options

Search for files named _everything.scss and suppress output to your Grunt process.

grunt.initConfig({
  sass_directory_import: {
    options: {
      quiet: true,
    },
    files: {
      src: ['src/scss/**/_everything.scss']
    },
  },
})

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

9-6-2013 - Initial release.