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-minimal-config

v1.1.2

Published

Grunt plugin loading splitted Gruntfiles for more readability.

Downloads

10

Readme

grunt-minimal-config

Grunt plugin loading splitted Gruntfiles for more readability. Useful if your Gruntfile.js is bloated by many plugins.

New simpler version !

See tag v0.5.4 for older implementation.

About

This plugin is used in solid web-base, a grunt boilerplate for solid web applications.

Installation

npm i grunt-minimal-config --save-dev

Usage

If you want to split your config file like so :

  • Gruntfile.js -> Default Gruntfile, nothing changes
  • Gruntfile-scripts.js -> all scripts tasks configuration
  • Gruntfile-styles.js -> all styles tasks configuration

Use this Gruntfile.js :

module.exports = function (grunt)
{
    grunt.initConfig({
        minimalConfig: {

            // Load sub-config files
            src: 'Gruntfile-*.js'
        }
    });
    grunt.loadNpmTasks('grunt-minimal-config');
};

src is a glob path, it can target folder like so : grunt-configs/*.js. But we advice to use Gruntfile-*.js for more readability in your file system.

Important : grunt.loadNpmTasks needs to be after minimalConfig configuration.

Sub-config file

Here is a sub-config file example, simple :

module.exports = function (grunt)
{
    // ------------------------------------------------------------------------- UGLIFY

    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.config('uglify', {
        options: {
            mangle: true,
            report: 'gzip',
            comments: false
        }
    });


    // ....
};

Shared parameters

The __ contains all shared options. Useful if you want to share some path or parameters between sub-config files.

Why not using the default grunt template system ?

Because with this we have a better error checking, some IDE can auto-complete and also __.src + 'Main.js' is more readable than <%= parameters.src %>Main.js with syntax coloration.

More complete Gruntfile.js with shared parameters between sub-configs :

module.exports = function (grunt)
{
    // ------------------------------------------------------------------------- CONFIG

    // Shared parameters
    let __ = {

        /**
         * Get --optimized CLI option.
         * If this option is added, bundles will be compressed.
         */
        optimizedTarget     : grunt.option('optimized') || false,

        // Glob extension to target all JS files
        allJsFiles          : '**/*.js',

        // Glob extension to target all Less files
        allLessFiles        : '**/*.less',

        // Assets output
        assetsDestination   : 'www/assets/',

        // Node module path
        nodeModulesPath     : 'node_modules/',

        // Project source files
        srcPath             : 'src/'
    };

    // Load and init minimal-config
    grunt.initConfig({
        minimalConfig: {

            // Load sub-config files
            src: 'Gruntfile-*.js',

            // Inject shared parameters in all loaded config files
            parameters: __
        }
    });
    grunt.loadNpmTasks('grunt-minimal-config');


    // ------------------------------------------------------------------------- TASKS

    grunt.registerTask('styles', 'less');

    // We can use shared parameters here too
    grunt.registerTask('default', (
        !__.optimizedTarget
        ? ['clean', 'styles', 'scripts']
        : ['clean', 'styles', 'scripts', 'uglify']
    ));

    grunt.registerTask('watch', ['default', 'watch']);
};

Shared parameters are as second argument inside sub-config files.

We advice using __ everywhere for simplicity and auto-completion with good IDEs :

module.exports = function (grunt, __)
{
    if (__.optimizedTarget)
    {
        // ...
    }

    // Configure less tasks
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.config('less', {

        common: {
            src: __.srcPath + 'common/Main.less',
            dest: __.assetsDestination + 'css/common.css'
        },

        myApp1: {
            src: __.srcPath + 'myApp1/Main.less',
            dest: __.assetsDestination + 'css/my-app-1.css'
        },

        myApp2: {
            src: __.srcPath + 'myApp2/Main.less',
            dest: __.assetsDestination + 'css/my-app-2.css'
        }
    });
};