miickel / gulp-angular-templatecache

Concatenates and registers AngularJS templates in the $templateCache.
MIT License
524 stars 103 forks source link

Better Browserify Stand-Alone Output #138

Closed ryanelian closed 6 years ago

ryanelian commented 7 years ago

Currently, using the option option moduleSystem: Browserify outputs the following line:

use strict'; module.exports = angular.module('templates').run(['$templateCache, ...

However, the variable angular is not actually defined prior to the call in the module file.

(It can be easily solved by defining var angular = require('angular'); in the module that requires the templates.js, but that would not be elegant.)

Hence, the output should look like this instead:

use strict'; module.exports = require('angular').module('templates').run(['$templateCache, ...

And then the module.exports should be the template name instead of the whole module!

module.exports = 'templates';

That way, the template module can be loaded into the angular application by just doing this (like most other angular module libraries):

use strict;

var templates = require('./templates');
var app = require('angular').module('myapp', [templates]);

Because currently the templates.js is the odd one out in my project:

'use strict';

// Hack: var angular should be at the top of the file because templates.js do not use require('angular')
var angular = require('angular');

// Hack: templates.js do not export the Angular module name but instead the whole angular module!
var templates = require('./templates').name;

var ryanValidator = require('./ryan-angular-validator');
var uib = require('angular-ui-bootstrap');
var animate = require('angular-animate');

var app = angular.module('aspnet', [templates, ryanValidator, uib, animate]);
simonua commented 6 years ago

@ryanelian, is this still relevant? If so, could you create a PR, please? If not, could you close the issue, please?

ryanelian commented 6 years ago

Should be still relevant but:

So closing the issue.