Include your sources into your HTML files automatically.
No longer maintained!
NOTE This repository is no longer actively maintained, but pull requests will still be handled.
This plugin requires Grunt
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 --save-dev grunt-include-source
The "includeSource" task
In your project's Gruntfile, add a section named
includeSource to the data object passed into
The base path to use when expanding files. Can be an array to support expanding files from multiple paths.
The base URL to use for included files in the final result.
For example, setting
public/ will result in files being included from
The templates for sources included in
ts files. Definition of single template overrides its default equivalent only.
As it was mentioned above, it is possible to override only necessary templates.
Map types that are not supported but have the same syntax as an existing type. For example:
includeSource:options:typeMappings:// CSHTML files uses the same syntax as HTML files.'cshtml': 'html'// LESS files use the same syntax as SCSS files.'less': 'scss'
A way of returning a custom filepath.
See grunt.file.expandMapping. If specified, this function will be responsible for returning the final dest filepath. By default, it joins dest and matchedSrcPath like so:
Remove the path component from all matched src files. The src file path is still joined to the specified dest.
HTML and CSHTML syntax
<!-- include: options_go_here_as_json -->
SCSS and LESS syntax
// include: options_go_here_as_json
/// <!-- include: options_go_here_as_json -->
The type of files that are being included.
Necessary for choosing the template for output. See
options.templates for currently supported types.
Supported types are dependend on the file type you include them from.
DEPRECATED: Use another Grunt plugin which is better suited for this usecase, like grunt-bower-install.
This plugin doesn't support the
main property for example and is mainly used for development purposes to directly include external sources.
Include files of the specified Bower component. The component should have a
bower.json meta data with a property called
This property should contain the files grouped by type, which are passed through the
"name": "package.name"..."sources":"js":"src/scripts/**/*.js""lib/compiled-templates.js""css": "src/styles/**/*.css"
Include the given files. Files are passed through the
grunt.file.expandMapping method (see
Set to override the
basePath set in the options.
Set to override the
baseUrl set in the options.
Ordering method to be used when including files. Currently supported methods are:
undefined(default) - included files are sorted by their paths alphabetically in ascending order.
'top-down'- files from the parent directory will be included before files from subdirectories.
To set the source file as the destination file use an
<!-- include: "type": "js", "files": "js/**/*.js" --><!-- /include -->
When includeSource is run it will keep the include comments and only update the includes inside it.
This works the same way for Less/Sass, by using
Configure your task like this:
index.tpl.html could contain, for example:
Index<!--Automatically include Bower components. Use the "sources" object in your bower.jsonto specify which source files are which.--><!-- include: "type": "css", "bower": "yourComponent" --><!--Include CSS files from a "tmp" directory, put there by another task.This shows how to override the default "basePath" set in the options.--><!-- include: "type": "css", "basePath": "tmp", "files": "styles/**/*.css" --><!-- include: "type": "js", "bower": "yourComponent" --><!-- include: "type": "js", "files": "scripts/**/*.js" -->
And the resulting file
index.html will look something like:
Index<!--Automatically include Bower components. Use the "sources" object in your bower.jsonto specify which source files are which.--><!-- include: "type": "css", "bower": "yourComponent" --><!--Include CSS files from a "tmp" directory, put there by another task.This shows how to override the default "basePath" set in the options.-->
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.