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

@ud-angular-builders/add-asset-index-plugin

v8.0.8

Published

@ud-angular-builders/add-asset-index-plugin is a Webpack Plugin using [@ud-angular-builders/custom-webpack](https://www.npmjs.com/package/@ud-angular-builders/custom-webpack) allowing to add link tag in Angular index.html output

Downloads

5

Readme

@ud-angular-builders/add-asset-index-plugin

@ud-angular-builders/add-asset-index-plugin is a Webpack Plugin using @ud-angular-builders/custom-webpack.

@ud-angular-builders/custom-webpack is an Angular Builder allowing to transform Angular Webpack configuration. It also allows to transform the output index.html. However, the index transformation hook is not inside webpack compilation and all the webpack context and configuration is lost. @ud-angular-builders/add-asset-index-plugin allows to add <link> tag in the index.html emitted by Angular during the webpack build process.

It is useful for activating cache busting for instance.

Example:

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>AngularTest</title>
    <base href="/">

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link rel="stylesheet" href="styles.0e5d74c770da8e85b22e.css">
    <link href="assets/bust-cached-font/libre-franklin/libre-franklin-v2-latin-400.8d503c823a91e889c0e7.woff2" as="font"
          rel="preload">
    <link href="assets/bust-cached-font/rubik/rubik-v7-latin-300.eb02199844b4e2a0871c.woff2" as="font" rel="preload">
    <link href="assets/bust-cached-font/rubik/rubik-v7-latin-400.1ecc21093d3c8aa44b3e.woff2" as="font" rel="preload">
    <link href="assets/bust-cached-font/rubik/rubik-v7-latin-500.d3fd715f234b8dcdd09d.woff2" as="font" rel="preload">
    <link href="assets/bust-cached-font/rubik/rubik-v7-latin-700.9aff6f99df5790ad5dbd.woff2" as="font" rel="preload">
</head>

<body>
    <app-root></app-root>
    <script type="text/javascript" src="runtime.26209474bfa8dc87a77c.js"></script>
    <script type="text/javascript" src="polyfills.8a55347372f0994ae121.js"></script>
    <script type="text/javascript" src="main.71b7733a833b42b9ab31.js"></script>
</body>

</html>

This documentation is for version 8 only. Find documentation for version 7 here.

Prerequisites:

Usage

First of all, install @up-angular-builders/custom-webpack

  1. npm i -D @up-angular-builders/custom-webpack
  2. In your angular.json:
    "projects": {
      ...
      "[project]": {
        ...
        "architect": {
          ...
          "[architect-target]": {
            "builder": "@up-angular-builders/custom-webpack:[browser|server|karma|dev-server]"
            "options": {
                  "customWebpackConfig" : { "HERE GOES THE CUSTOM WEBPACK OPTIONS" }
            }
    Where:
    • [project] is the name of the project to which you want to add the builder
    • [architect-target] is the name of build target you want to run (build, serve, test etc. or any custom target)
    • [browser|server|karma|dev-server] one of the supported builders - browser, server, karma or dev-server
  3. If [architect-target] is not one of the predefined targets (like build, serve, test etc.) then run it like this:
    ng run [project]:[architect-target]
    If it is one of the predefined targets, you can run it with ng [architect-target]

For example

  • angular.json:
    "projects": {
      ...
      "example-app": {
        ...
        "architect": {
          ...
          "build": {
            "builder": "@up-angular-builders/custom-webpack:browser"
            "options": {
                "customWebpackConfig": {
                    "path": "./extra-webpack.config.js"
                },
            }
  • Run the build: ng build

Builders

For more details on custom-webpack, please check the @up-angular-builders/custom-webpack. You can check a full example here

Now, you can write the webpack configuration in ./extra-webpack.config.js:

const path = require('path');
const { AddAssetIndexPlugin } = require('@up-angular-builders/custom-webpack');

module.exports = buildParameters => {
    // the properties of buildParameters are
    // const { builderContext, buildOptions, baseWebpackConfig } = buildParamters;

    const configuration = {
        module: {
             rules: [
                {
                    test: /\.css$/,
                    loader: 'css-loader',
                    options: {
                        name: `[name][hash].[ext]`,
                    },
                 }
            ],
        },
        plugins: [
            new webpack.DefinePlugin({
              ENVIRONMENT: JSON.stringify('browser')
            }),
            new webpack.NormalModuleReplacementPlugin(/(.*)\$environment\$(\.*)/, function (resource) {
              resource.request = resource.request.replace(/\$environment\$/, 'browser');
            }),

            new AddAssetIndexPlugin([
                {
                    filepath: 'src/font/**/*.woff2',
                    attributes: {
                        as: 'font',
                        rel: 'preload'
                    },
                    // deployUrl: 'public/deploy',
                    hash: true,
                    place: 'head',
                    sri: true,
                    outputDir: filepath => {
                        const split = filepath.split('src/font/');
                        const newpath = path.join('assets/bust-cached-font', split[1]);

                        return path.dirname(newpath);
                    }
                }
            ], builderParameters)
        ]
    };

    // ovveride allows to merge or override the Angular webpack configuration
    // return configration directly is the same as the following.
    return { configuration, ovveride: false };
};

The result will be the html example showed at the beginning.