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-multi-build-plugin

v1.1.0

Published

simplifies creation of HTML file for multi-build configuration

Downloads

1,749

Readme

html-webpack-multi-build-plugin

This plugin simplifies the creation of script tags for module and nomodule for a webpack multi build configuration.

npm version

Why do you want to do this?

Most developers still transpile their code to ES5 and bundle it with polyfills to provide support for older browsers. But for newer browsers this transpiled code is unnecessary and probably slower then ES6+ code. The Idea is to create two bundles, one modern es6+ bundle and one legacy es5 bundle.

What? How do you do that?

The solution is to provide two script tags, one with type=module (es6+ code) and one with "nomodule" (es5 code). Modern Browser will now only load the script tag with type=module while legacy browser only load the script tag with "nomodule".

Will some browser still download both bundles?

Some browser like Safari, IE11, Edge are downloading both bundles, but only executing one. This plugin has integrated a clever fix for this. By creating a script tag with module / nomodule which dynamically injects the actual script tags for the javascript resources.

<script type="module">
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'vendors~app_60d33517957366ff05a8.js';
    document.body.appendChild(script);
</script>

Why do i need this addon?

This plugin for html-webpack-plugin generates script tags for module and nomodule for a webpack multi build configuration.

Async CSS Loading

The included template add's tags for async (non blocking) css

<link href="app.css" rel="stylesheet" media="nope!" onload="this.media='all'">

Read about webpack multi build configuration

https://webpack.js.org/configuration/configuration-types/#exporting-multiple-configurations

How to use this addon?

Check out my Example Project

Summarized

Package.json

    "scripts": {
        build:multi": "webpack --env.build=multi"
    }

webpack.config

    // Legacy webpack config needs to include 'legacy' 
    config.output.filename = '[name]_legacy.js';

    // Modern webpack config must not include 'legacy'
    config.output.filename = '[name].js';

    // Both webpack configs must include htmlWebpackPlugin and htmlWebpackMultiBuildPlugin
    const htmlWebpackMultiBuildPlugin = require('html-webpack-multi-build-plugin');
    const multiBuildMode = process.env.build === 'multi'
    const template = multiBuildMode 
    ? require.resolve('html-webpack-multi-build-plugin/template.ejs') 
    : require.resolve('html-webpack-plugin/default_index.ejs');
    
    config.plugins: [
        new htmlWebpackPlugin(
            {
                inject: !multiBuildMode,
                template
            }
        )
        new htmlWebpackMultiBuildPlugin()
    ]

Sources

https://philipwalton.com/articles/deploying-es2015-code-in-production-today/
https://github.com/philipwalton/webpack-esnext-boilerplate
https://jakearchibald.com/2017/es-modules-in-browsers/
https://github.com/jantimon/html-webpack-plugin/issues/782
https://github.com/philipwalton/webpack-esnext-boilerplate/issues/1