├── .gitignore ├── package.json ├── index.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | node_modules/ 4 | npm-debug.log 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel-elixir-ngtemplatecache", 3 | "version": "0.3.1", 4 | "description": "Laravel Elixir extension for generating AngularJS an templateCache module", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "laravel", 11 | "elixir", 12 | "templatecache", 13 | "htlmmin", 14 | "gulp" 15 | ], 16 | "author": "Peter Reisz ", 17 | "contributors": [ 18 | "Rafael César Neves " 19 | ], 20 | "license": "MIT", 21 | "dependencies": { 22 | "gulp-angular-templatecache": "^1.7.0", 23 | "gulp-htmlmin": "^1.1.3", 24 | "extend": "^3.0.0" 25 | }, 26 | "devDependencies": {}, 27 | "repository": { 28 | "type": "git", 29 | "url": "https://github.com/peterreisz/laravel-elixir-ngtemplatecache" 30 | }, 31 | "bugs": { 32 | "url": "https://github.com/peterreisz/laravel-elixir-ngtemplatecache/issues" 33 | }, 34 | "homepage": "https://github.com/peterreisz/laravel-elixir-ngtemplatecache" 35 | } 36 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'), 2 | extend = require('extend'), 3 | htmlmin = require('gulp-htmlmin'), 4 | templateCache = require('gulp-angular-templatecache'), 5 | elixir = require('laravel-elixir'), 6 | gulpIf = elixir.Plugins.if, 7 | sourcemap = elixir.Plugins.sourcemaps, 8 | config = elixir.config; 9 | 10 | elixir.extend('ngTemplateCache', function(src, output, basedir, options) { 11 | 12 | options = extend(true, { 13 | enabled: { 14 | htmlmin: config.production 15 | }, 16 | templateCache: { 17 | standalone: true 18 | }, 19 | htmlmin: { 20 | collapseWhitespace: true, 21 | removeComments: true 22 | } 23 | }, options); 24 | 25 | var paths = new elixir.GulpPaths() 26 | .src(src || '/**/*.html', basedir || config.assetsPath + '/templates') 27 | .output(output || config.get('public.js.outputFolder')); 28 | 29 | new elixir.Task('ngTemplateCache', function() { 30 | 31 | return gulp.src(paths.src.path) 32 | .pipe(gulpIf(config.sourcemaps, sourcemap.init())) 33 | .pipe(gulpIf(options.enabled.hmtlmin, htmlmin(options.htmlmin))) 34 | .pipe(templateCache(options.templateCache)) 35 | .pipe(gulpIf(config.sourcemaps, sourcemap.write('.'))) 36 | .pipe(gulp.dest(paths.output.baseDir)) 37 | .pipe(new elixir.Notification('Angular templatecache generated.')); 38 | 39 | }).watch(paths.src.path); 40 | 41 | }); 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Laravel Elixir ngTemplateCache 2 | 3 | [Laravel elixir](https://github.com/laravel/elixir) extension for generation angularjs templatecache module. 4 | 5 | Read more about templateCache 6 | * Angularjs API documentation: https://docs.angularjs.org/api/ng/service/$templateCache 7 | * gulp-angular-templatecache: https://github.com/miickel/gulp-angular-templatecache 8 | 9 | ## Features 10 | 11 | * Generate template cache module 12 | * So the angularjs could load all template with one http request 13 | * Compress html in production mode 14 | * Generate sourcemap 15 | 16 | ## Install 17 | 18 | ``` 19 | npm install --save-dev laravel-elixir-ngtemplatecache 20 | ``` 21 | 22 | ## Usage 23 | 24 | ### Example *Gulpfile.js*: 25 | 26 | ```javascript 27 | var elixir = require('laravel-elixir'); 28 | 29 | require('laravel-elixir-ngtemplatecache'); 30 | 31 | elixir(function(mix) { 32 | mix.ngTemplateCache(); 33 | }); 34 | ``` 35 | 36 | All arguments all optional, meaning of them: 37 | - `src` - template file pattern, these files located inside the base directory and these will be aggregated into one angularjs module, default value: `/**/*.html` 38 | - `outputDir` - where to put the generated module, default value: `elixir.config.jsOutput` which means `public/js` if you left untoched the elixir configuration 39 | - `baseDir` - base directory for searching template files, default value: `elixir.config.assetsDir + 'templates'` which means `resources/assets/templates` in case you haven't configured the elixir in another way 40 | - `options` - configuration options for this plugin and for these 3rdparty libraries used by the plugin. 41 | - `templateCache` - This plugin use the [gulp-angular-templatecache]https://github.com/miickel/gulp-angular-templatecache#api) for the templatecache module generation. You can configure that plugin here. Default options: 42 | ``` 43 | { 44 | standalone: true 45 | } 46 | ``` 47 | - `htmlmin` - Options for html minification, you find possible parameter in the [html-minifier](https://github.com/kangax/html-minifier#options-quick-reference) documentation. Default options: 48 | ``` 49 | { 50 | collapseWhitespace: true, 51 | removeComments: true 52 | } 53 | ``` 54 | 55 | 56 | ### Complex example *Gulpfile.js* containing all default values: 57 | 58 | ```javascript 59 | var elixir = require('laravel-elixir'); 60 | 61 | require('laravel-elixir-ngtemplatecache'); 62 | 63 | elixir(function(mix) { 64 | mix.ngTemplateCache('/**/*.html', 'public/js', 'resources/assets/templates', { 65 | enabled: { 66 | htmlmin: true // in production, false in development mode 67 | }, 68 | templateCache: { 69 | standalone: true 70 | }, 71 | htmlmin: { 72 | collapseWhitespace: true, 73 | removeComments: true 74 | } 75 | }); 76 | }); 77 | ``` 78 | 79 | ### Example Angular Usage: 80 | 81 | Include the templates file into your html: 82 | ```html 83 | 84 | ``` 85 | And then add the `templates` module to the main module of your angularjs application: 86 | 87 | ```javascript 88 | angular.module('app', ['templates', '...']); 89 | ``` 90 | 91 | Use the template: 92 | ```html 93 | 94 | ``` 95 | This will require a file `BASEDIR/foo/bar.html`, so you don't have to put the `BASEDIR` inside the url. 96 | 97 | ## Changelog 98 | 99 | __0.3.1__ 100 | - Added config option to toggle html-min usage 101 | 102 | __0.3.0__ 103 | - Refactor path handling to get the ability to ignore files with gulp/glob patterns 104 | 105 | 106 | __0.2.0__ 107 | - Upgrade to laravel-elixir 3.0 108 | - Upgrade dependencies 109 | 110 | 111 | __0.1.0__ 112 | - Initial release 113 | 114 | ## TODO 115 | 116 | - Tests 117 | - Source code documentation 118 | 119 | ## License 120 | 121 | MIT --------------------------------------------------------------------------------