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

ng-cli-hooks

v16.0.0

Published

Hooks for the Angular CLI

Downloads

2,598

Readme

ng-cli-hooks

MIT License npm version npm downloads Known Vulnerabilities

Buy me a coffee

Hooks for the angular-cli

Unfortunately I don't have much time to take care of this project, so please contribute when new versions of Angular are released. As an alternative to this package, I recommend taking a look at the angular-builders repo. They are much faster when new Angular versions are released.

This documentation is for version 16 only

Documentation for other versions could be found here:

Getting Started

Install the package:

npm install --save-dev ng-cli-hooks

Update your angular.json file:

{
  ...
  "projects": {
    "app": {
      ...
      "architect": {
        "build": {
          "builder": "ng-cli-hooks:browser",
          "options": {
            "optionsHook": "hooks/options.js",
            "webpackHook": "hooks/webpack.js",
            "indexHtmlHook": "hooks/index-html.js",
            ...

This Plugin contains hookable builders for

  • browser
  • dev-server
  • server

Hooks

Currently this plugin contains three different hooks: optionsHook, webpackHook and indexHtmlHook.

optionsHook

This hook modifies the options for the builder at build-time.

Example: hooks/options.js

module.exports = function (options) {
    if (process.env.APP_BRANDING) {
        var branding = process.env.APP_BRANDING.trim();
        if (options.assets) {
            options.assets = options.assets.map(asset => {
                if (asset.input === 'src/assets') {
                    asset.input = `src/branding/${branding}/assets`;
                }
                return asset;
            });
        }
    }

    return options;
}

indexHtmlHook

This hook modifies the generated index.html at build-time. It is only available for the builders browser and dev-server.

Example: hooks/index-html.js

module.exports = function(content, options) {
    content = content.replace('Ionic App', 'Example App');
    return content;
}

webpackHook

This hook can be used to modify the generated webpack-config of angular-cli or to replace it.

Modify the generated webpack-config

During the development of this hook it may be necessary to clear the Angular cache.

Example: hooks/webpack.js

function replaceAngularCompilerPlugin(plugins) {
  const plugin = plugins.find(p => p.pluginOptions && p.pluginOptions.directTemplateLoading);
  const options = plugin.pluginOptions;
  options.directTemplateLoading = false;
}

module.exports = function (generatedWebpackConfig, options) {  
  generatedWebpackConfig.module.rules.unshift({
    test: /\.html$/,
    loader: 'string-replace-loader',
    options: {
        search: /Welcome/ig,
        replace: () => 'Welcome to ng-cli-hooks',
        flags: 'g'
    }
  });

  replaceAngularCompilerPlugin(generatedWebpackConfig.plugins);

  return generatedWebpackConfig;
}

Replace the generated webpack-config

If hooks/webpack.js exports a webpack-config-object, than the generated webpack-config will be replaced by your own.

Changelog

16.0.0

  • Support for Angular 16

15.0.0

  • Support for Angular 15

13.0.0

  • Support for Angular 13

12.0.0

  • Support for Angular 12

11.0.0

  • Support for Angular 11

8.0.0

  • Support for Angular 8
  • Removed builders for extract-i18n and cordova-build
  • Added indexHtmlHook to hook into the index.html build.

7.0.0

  • Major version of ng-cli-hooks now equals the Angular version (use [email protected] to work with Angular 7.x.x)

1.1.0

  • added ng-cli-hooks:cordova-build for Ionic 4 projects.