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

angular-hot-reloader

v0.0.3

Published

Hot reloading template, services, and controller for Angular 1.X

Downloads

51

Readme

angular-hot-reloader

Hot Reload templates, controller and services in Angular1.X!!

The angular hot reloader is a suite of webpack loaders that enable hot reloading for templates, controller and services in Angular 1.X, leveraging the power of Webpack's Hot Module Reloader, with a minimal contract.

What does it do ?

For now, it enables hot module reloading for templates, controller methods (except constructors), and services. NEW: Update with an typescript example !

What do I need to make it work ?

These loaders were written to work with a project using Webpack, ES6+Babel, Angular 1.X and best practices from @johnpapa and @scottmoss from AngularClass. Needless to say, it was largely inspired by the great work of @danabramov.

The main requirements are :

  • One file, one ES6 module, one purpose.
  • A strong convention on naming your files. The loaders are inferring controllerNames and serviceNames based on the name of the file.
  • An ES6-component style of writting angular applications

How do I make it work ?

If your code respects the minimal contract, you just need to npm install or fork this project, and add preloaders for controller and services and post loaders for your templates:

var componentHotLoader = require.resolve('../loaders/component-loader');
var serviceHotLoader = require.resolve('../loaders/service-loader');
var jadeHotLoader = require.resolve('../loaders/jade-loader');


// add componentHotLoader and serviceLoader
(webpackConf.module.preLoaders = webpackConf.module.preLoaders || []).push(
  { test: /\.component\.js$/, loader: componentHotLoader, exclude: [/client\/lib/, /node_modules/, /\.spec\.js/] }
);
(webpackConf.module.preLoaders = webpackConf.module.preLoaders || []).push(
  { test: /\.service\.js$/, loader: serviceHotLoader, exclude: [/client\/lib/, /node_modules/, /\.spec\.js/] }
);
(webpackConf.module.postLoaders = webpackConf.module.postLoaders || []).push(
  { test: /\.html/, loader: jadeHotLoader }
);

And ... you're done. You can add or remove html in your templates, add scope bindings, change controller methods, change service methods (currently only supports Services and not factories)

Requirements in detail:

Component Loader

  • You must have one file per controller and export the controller or the angular.module with the controller invoked.
  • You must use functions that have a name property (e.g. class HomeController { or function HomeController()
  • You must have a distinct filenaming strategy. Currently our loader looks for the folder name of the file, adds Controller to it, and then finds a reference to the old controller thanks to angular's injector, and then updates its methods one by one with the ones from nameController in your new module. So for instance if you have a file named home.controller.js under components/home, the loader will look for <home></home> directives and updates the HomeController reference in angular's scope with HomeController's new methods`
  • Currently, we use isolateScope on every components (which is also the default with the new Angular Component method), if not, you'll have to change the way you get the controller reference. We also use controller as vm for all our component, so we get our instances with this line:

angular.element(document).find('directiveName').isolateScope().vm

Template Loader

  • You must have one file per template (although this may not be mandatory to achieve hot reloading, it's just the way it is written)
  • The template file should be named according to the same startegy, i.e. home.html for <home></home> directive

How does it work ?

The loaders are just adding a little piece of code to each file that can be hot loaded to declare themselves as hot-reloadable to webpack, and then to do some hacky magic to make angular aware of the changes, recompiling the templates against the scope, and change the methods of the controller prototype.

Does it really work ?

Well our current app uses angular 1.X with es6, so it was written to ease our developement experience and it's been a great addition to our tooling ! It works really good for what we need but there are edge-cases where it doesn't. Feel free to post an issue to pinpoint failing cases

It's 2017, how about angular2 ?

The methodology applied here could be easily ported to angular2