Ryan Harvey edited this page Nov 26, 2013 · 4 revisions

Replacement Blocks

Replacement blocks (blocks) are regions in a source file that will be updated by the task. Blocks must be configured in the source file and in the Grunfile.js configuration for the task. Comments are placed in the source file to define anchors that mark the beginning and end of the block. Two comment styles are supported for HTML and JavaScript/TypeScript files.

Start Anchor

fileblock:<template> <name>

template: This must match the name of a custom template or one of the supplied templates js, css, ref, or raw.

End Anchor


HTML Example

<!-- fileblock:js appScripts -->
<!-- endfileblock -->

TypeScript Example

/* fileblock:ref references */
/* endfileblock */

Task Configuration

Each source file in the Gruntfile configuration defines a blocks array. Each element in this array is a block configuration object.

Example Configuration

fileblocks: {
  my_target: {
    src: 'index.html'
    blocks: {
      'scripts': { src: 'app/js/*.js' /* Optional block level options */}
      /*... additional block configurations */

Block Configuration Object Properties


Type: String|String[] File globbing patterns used to find source files.

template (optional)

Type: String The name of the template for the block. This property overrides the template name specified in the start anchor.

Block Level Options

Any of the task options may be specified at the block level.

Advanced Block Configuration Properties

The cwd, flatten, ext, rename, and matchBase options may be added to a block configuration object in order to build the files list dynamically.