npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-require-angular

v0.7.1

Published

require() AngularJS modules/dependencies without having to type require()

Downloads

9

Readme

gulp-require-angular

Build Status

npm install gulp-require-angular --save-dev

What

A gulp plugin which scans your AngularJS project source files and generates a single js file full of require() statements which can be then used as an entry file for Browserify or Webpack. Only AngularJS modules which appear in the dependency tree of your mainModule are require()'d. Supports modules installed with bower too.

Why

So that the majority of your code base will be automatically require()'d in the correct order while still enabling you use require() where you want.

How

See demos for working examples. Also here's a fork of angular-seed with gulp-require-angular and browserify

Write your app using standard AngularJS syntax. e.g.

app.js

angular.module('myApp', ['moduleA']);

moduleA/moduleA.js

angular.module('moduleA', []);

moduleA/moduleA.ctrl.js

angular.module('moduleA').controller('abc',function ($scope) {
});

Use the plugin as part of your gulp task

var gulp = require('gulp');
var requireAngular = require('gulp-require-angular');

gulp.task('requireAngular', function () {
	gulp.src(['src/**/*.js'])
        .pipe(requireAngular('myApp'))
        .pipe(gulp.dest('src/'))
});

The above will generate a file named (by default) gulp-require-angular.generated.js which will contain:

require('./app.js');
require('./moduleA/moduleA.js');
require('./moduleA/moduleA.ctrl.js');

You then use gulp-require-angular.generated.js as the entry file for Browserify or Webpack. The benefit of this is that all your Angular is automatically required, while you can still use require() inside your controllers / services / directives to pull in non angular modules / templates / css depending on your Browserify transforms / Webpack loaders. e.g. you might have a charting directive that uses an existing a non angular charting library. One of the cleanest ways to pull in that external library dependency is to require() it:

var nonAngularPieChart = require('./nonAngularPieChart');

angular.module('pieChart', []).directive('pieChart', function () {
	return {
		restrict: 'A',
		link: function (scope, element, attrs) {
			var options = scope.$eval(attrs.chartOptions);
			nonAngularPieChart(element, options);
		}
	};
});

Usage

The plugin will only find modules if angular.module is used. If you alias the variable angular or have modules in minifed code, e.g. a.module, it will not be found. You must use unminified versions of third party modules like ui-router, ngResource etc in your project src.

The function

requireAngular('mainModule', options);

mainModule

mainModule is the name of the module entry point used to calculate the module dependency tree. This is your top level module, and is going to be the same module name found in ng-app.

options

Object with the following default properties

{		
	filename: 'gulp-require-angular.generated.js',
	rebase: './',
	base: '',	
	errorOnMissingModules: false,
	bower: false,
	mainBowerFiles: {}
}
filename

The name of the generated .js file.

rebase

The base path to apply to all require statements.

base

The directory to place the generated file. By default it is the base path of everything in gulp.src

errorOnMissingModules

When a module appears in the dependency tree, but cannot be found in a file, emit an error or not.

bower

To look for bower installed packages or not. If true, bower.json must be present. Will only look for bower packages which are installed, i.e. listed as dependencies in bower.json.

mainBowerFiles

Options object to pass through to bower-main-files