gulp-inline-ng2-template
This is a fork of gulp-inline-ng2-template.
note:
- 4.0.1 -
- fixed for partial process
- added original url to processors - if you want to use a bundler and to leave the files processing to that bundler, replace the text with require
- grave accent for style is optional - useStyleGraveAccent option, default useStyleGraveAccent = true
Inline Angular HTML and CSS files into JavaScript ES5/ES6 and TypeScript files (and possibly more - not tested).
This plugin uses the ES6 template strings syntax by default (which requires the use of a transpiler -typescript, babel, traceur- to produce valid ES5 files) but you can opt-in for ES5 one.
Very convenient to unit test your component or bundle your components/application (avoid extra HTTP request and keeps your source clean).
TOC
- Installation
- Configuration
- Example usage
- Browserify transform example
- How it works
- Contribute
- Contributors
- Todo
- Licence
Installation
npm install gulp-inline-ng2-template --save-dev
Configuration
Options
You can pass a configuration object to the plugin.
defaults = base: '/' // Angular2 application base folder target: 'es6' // Can swap to es5 indent: 2 // Indentation (spaces) useRelativePaths: false // Use components relative assset paths removeLineBreaks: false // Content will be included as one line templateExtension: '.html' // Update according to your file extension templateFunction: false // If using a function instead of a string for `templateUrl`, pass a reference to that function here {/* ... */} {/* ... */} {/* ... */} supportNonExistentFiles: false // If html or css file do not exist just return empty content;
Processors configuration
/** * Processor function call signature and type return * * @Param * @Param * @Param * @Param * @Return */
Processor Examples
Minify template file before inlining them
;; const pluginOptions = base: mySrcPath templateProcessor: minifyTemplate; { try var minifiedFile = htmlMinifier; ; catch err ; }
Credit @lcrodriguez
Template function
Inside your component: templateUrl: templateFunc('app.html')
/** * Template function call signature and type return * * @Param{String} filename * @Return{String} returned filename */templateFunction: function (filename) { // ... return newFilename;}
CustomFilePath configuration
/** * Custom function name call signature and type return * * @Param * @Param * @Return */
Example usage
//...var inlineNg2Template = ; var result = gulp ; return resultjs ;
Browserify transform example
Example transform function to use with Browserify.
// ng2inlinetransform.jsvar ng2TemplateParser = ;var through = ;var options = target: 'es5'; { return ;}
// gulp taskreturn
Thanks to @zsedem
How it works
app.html
Hello {{ world }}
app.css
app.ts
;@@ {}
result (app.ts)
;@@ {}
Contributors
Todo
- Append styles into
styles
View config property if it exist - Add support for source maps
- Add option
skipCommented
Licence
MIT