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

bs-injular

v0.7.0

Published

Inject angular templates, controllers and directives with Browsersync

Downloads

19

Readme

Injular

npm version build status codecov Gitter

Inject angular templates, controllers, directives and components with Browsersync

AngularJS 1.x hot reloading. This is a plugin for the awesome BrowserSync.

Install

$ npm install --save-dev bs-injular injular@legacy browser-sync

Try it

You can try a live demo of the client code by clicking here.

If you want to try it with the server code, run the following commands:

git clone https://github.com/tfoxy/bs-injular-demo.git
cd bs-injular-demo
npm install && bower install
gulp serve

Modify the *.html, *.controller.js and *.directive.js files inside src/app and watch the changes instantly.

Click here to watch GIF of demo

Setup

Minimal

var browserSync = require('browser-sync');
var bsInjular = require('bs-injular');

browserSync.use(bsInjular, {
  templates: '**/app/**/*.html',
});

browserSync({
  /* browserSync options */
});

This will inject all html files inside an app folder.

Recommended

var browserSync = require('browser-sync');
var bsInjular = require('bs-injular');

browserSync.use(bsInjular, {
  templates: '**/app/**/*.html',
  controllers: '**/app/**/*.controller.js',
  directives: '**/app/**/*.+(directive|component).js',
  filters: '**/app/**/*.filter.js',
  angularFile: '/bower_components/angular/angular.js',
  moduleFile: '**/app/index.module.js'
});

browserSync({
  /* browserSync options */
});

This supports template, controller, directive, component and filter injection.

Configuration

If you want to inject controllers, you must provide the following properties:

{
  controllers: '**/app/**/*.controller.js',
  moduleFile: '**/app/index.module.js'
}

The module file is necessary to get the $controllerProvider in the config phase so that the controllers can be injected later.

If you want to inject directives and components, you must provide the following properties:

{
  directives: '**/app/**/*.+(directive|component).js',
  angularFile: '/bower_components/angular/angular.js',
  moduleFile: '**/app/index.module.js'
}

The module file is necessary to get the $compileProvider in the config phase so that the directives can be injected later.
The angular file is necessary to keep track of the directives present in a file.

WARNING: The controller files must retrieve the module using angular.module() and only use the controller recipe. The same applies to directives.

angular
  .module('myProject')
  .controller('Controller', Controller);

function Controller() {
  // Controller code here
}

If there is any other angular recipe, it will be ignored.

Also, when using the BrowserSync API, you must only reload the changed script file:

browserSync.reload('app/main/main.controller.js')

When browserSync.stream is used with multiple source files, it will reload the page.
If you use generator-gulp-angular, you must change the watches behaviour so that only the changed script is reloaded.
See: scripts.js watch.js

Version support

Supports AngularJS from 1.2 to 1.5 . Supports all modern browsers and IE >= 8. NOTE: for IE8, you must set supportIE8 option to true:

browserSync.use(bsInjular, {
  supportIE8: true,
  /* bs-injular options */
});

Help

If you have some problems with the configuration, you can get more information by setting the log level of Browsersync to debug:

browserSync({
  logLevel: 'debug',
  /* browserSync options */
});

If you get the following messages when changing a file:

[BS] [Injular] No moduleFile was matched: **/app/index.module.js
[BS] [Injular] No angularFile was matched: /bower_components/angular/angular.js

you can check if those patterns match any of the requests made to the server.

If you need more help, you can submit an issue or leave a message in gitter.

What's missing

  • Support for javascript bundlers: webpack, browserify, rollup.js
    Template injection works. Scripts changes reload the browser.

  • Injection of service and factory recipes.

  • Show the file and line number when an error is thrown in an injected script.
    Currently, the script is evaluated using Function.

Resources

Inspired by shakyShane/html-injector and pashaigood/browser-sync-angular-template