Skip to content

Grunt plugin to concatenate and minify javascript files and html templates into a single, dojo-readable cache file

License

Notifications You must be signed in to change notification settings

CognosExt/grunt-dojo-alt-build

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grunt-dojo-alt-build

Concatenate and minify all javascript files and html templates into a single, dojo-readable file

Getting Started

This plugin requires Grunt ~1.0.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-dojo-alt-build --save-dev

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

grunt.loadNpmTasks('grunt-dojo-alt-build');

or by using the load-grunt-tasks plugin:

require('load-grunt-tasks')(grunt);

The "dojo_alt_build" task

Overview

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

grunt.initConfig({
  dojo_alt_build: {
    target_name: {
        options: {
          pkgs: {
            // list the local packages in dojoConfig that should be built.
          },
          uglify: {
            // Standard uglify options, eg. screwIE8: false, banner: '/** My (c) **/'
          }
        },
        files: {
          // list the files to include in the build here.
          // see grunt documentation for different structure options
        }
    }
  }
});

Options

options.pkgs

Type: Object

An object listing the local packages in dojoConfig that should be built.

options.uglify

Type: Object

An object as passed onto the uglify command. See Grunt-Uglify documentation.

files

Type: file list

A list of js modules and html templates to be concatenated and minified. (note: this is a sibling to, not within, the options object)

See Grunt documentation for different structure options.

Usage Examples

For a project with dojoConfig:

var dojoConfig = {
  parseOnLoad: true,
  packages: [{
    name: 'app',
    location: locationPath + 'js/app'
  }, {
    name: 'components',
    location: locationPath + 'js/components'
  }, {
    name: 'config',
    location: locationPath + 'js/config'
  }]
};

an app target for the dojo_alt_build task looks like this (assuming a config module that should be excluded from the build process).

dojo_alt_build: {
  app: {
    options: {
      pkgs: {
        // list the local packages in dojoConfig that should be built.
        // (don't include config package here)
        'app': 'js/app',
        'components': 'js/components'
      }
    },
    files: {
      'release/js/app.min.js': [
        // all js and html files from the js folder except config
        'js/**/*.js',
        'js/**/*.html',
        '!js/config/*'
      ]
    }
  }
}

and release/index.html would include a script tag to import the built modules, and a require statement to the module that kicks off the application.

<script src="js/app.min.js"></script>
<script>
  <!-- Application Entry Point -->
  require(['app/controller']);
</script>

Contributing

todo

Release History

todo

About

Grunt plugin to concatenate and minify javascript files and html templates into a single, dojo-readable cache file

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%