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

html-webpack-select-assets-plugin

v0.1.0

Published

Select certain output files to the html file.

Downloads

13

Readme

html-webpack-select-assets-plugin

Select certain output files to the html file. Works with newer html-webpack-plugin versions.

Build Status

NPM

Only for webpack@5 and html-webpack-plugin@5 or higher.

Usage

  1. Install via npm i -D html-webpack-select-assets-plugin.
  2. Add to your webpack config AFTER HtmlWebpackPlugin.
const HtmlWebpackSelectAssetsPlugin = require('html-webpack-select-assets-plugin');
// OR
import HtmlWebpackSelectAssetsPlugin from 'html-webpack-select-assets-plugin';

// And for webpack config
{
    entry: {
        app: join(__dirname, './src/entry.js'),
        other: join(__dirname, './src/other.js'),
    },
    // ...
    plugins: [
        new HtmlWebpackPlugin({
            filename: (entry) => `${entry}.html`,
            template: join(__dirname, './src/index.html'),
        }),
        new HtmlWebpackSelectAssetsPlugin({
            selector: 'smart',
        }),
    ]
}

The plugin takes a configuration argument with a key called selector. It will help you to select assets for the specified output html.

The typical or most powerful usage case is when you deal with multiple html pages:

  • You have multiple entry for webpack entry config;
  • Only one HtmlWebpackPlugin instance and config with filename: (entry) => \${entry}.html`` to generate multiple html files (one-to-one correspond to each entry js file).

The problem is that HtmlWebpackPlugin will inject all (entry) assets files to each html file. What if you only want the corresponding entry's assets? This is why html-webpack-select-assets-plugin here -- select assets corresponding to entry.

Powerful selector option

  • "smart": only select assets corresponding to each entry automatically. This means if you want to generate app.html for entry:app.js, only app.js and assets imported by app.js will be injected.

  • function selector(asset:HtmlTagObject, context:SelectorContext, type:AssetType):boolean: you can write your custom selector function to choose assets flexibly.

    • HtmlTagObject: {attributes,meta,tagName}, the type is defined by html-webpack-plugin and represents the asset.
    • SelectorContext: {entry:string, outputName:string, entryFiles:string[]}, the context info for the asset. entry means entry name, outputName is current generated html file's name, and entryFiles means all assets associated with the entry.
    • AssetType: enum "script"|"style"|"meta", means the type of the asset.