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

usemin-webpack-plugin

v1.0.7

Published

Webpack Plugin for using the min.js version of a library at build time.

Downloads

2

Readme

Usemin plugin for Webpack

npm GitHub npm bundle size

A Webpack Plugin to use the min.js version of a library at build time.

About

Sometimes the .min.js file version of a javascript library is not coming from the actual raw .js file. Like in the case of p5.js, where, as they say, the minified file doesnt' include some logic found in the big javascript file:

This file is a minified version of the p5.js file (...) and does not include the friendly error system.

So a whole part of the library, helpful for the development phase, but not necessarily for the production release, is missing in p5.min.js.

To show some numbers, below you can see the actual size for p5.js version v0.10.2:

| File | Size | Explanation | | ------------- |-------------| -----| | p5.js | 4,207 KB | The original js file | | p5.min.js | 545 KB | The .min file coming with the library | | p5.min.js | ~1,500 KB | The .min file generated from the original js file |

Knowing all this, what Usemin-Webpack-plugin does, is to allow one to specify inside the Webpack config file, a series of libraries that will have the .js and .min.js swapped at build time. After the build process is completed, the files will be restored to the initial state.

Used together with CompressionWebpackPlugin (especially with the brotliCompress algorithm), this plugin will allow us to get very small bundle sizes, for eg. in the case of p5.js, a final bundle size of 118 KB!

Install

npm install usemin-webpack-plugin --save-dev

or short version

npm i -D usemin-webpack-plugin

Options and Defaults

entries: []

- Defaults to []
- Holds on array of objects, where each object
  describes a path and a fileName for a library
  that needs to use the .min.js file at build time.

Eg:
    new UseminWebpackPlugin({
        entries: [
            {
                path: "node_modules/p5/lib",
                fileName: "p5"
            },
            {
                path: "node_modules/sockjs-client/dist",
                fileName: "sockjs"
            }                
        ]
    })

disabled: boolean

- Defaults to false
- Set it to true to disable the whole plugin, without
  the need to remove or comment out the plugin entry in
  the Webpack config file.        

noLogs: boolean

- Defaults to true
- Set it to true to disable writing all the logs during the
  WebPack build process.

Usage

const UseminWebpackPlugin = require("usemin-webpack-plugin");

const webpackConfig = {
    plugins: [
         /**
         * See `Options and Defaults` for information
         */
        new UseminWebpackPlugin()
    ],
};

module.exports = webpackConfig;

Examples

This is a modified version of WebPack's Plugin documentation that includes the Usemin Webpack Plugin.

const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');

const UseminWebpackPlugin = require("usemin-webpack-plugin");

module.exports = {
    entry: './path/to/my/entry/file.js',
    output: {
        filename: 'my-first-webpack.bundle.js',
        path: path.resolve(__dirname, 'dist'),
    },
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/,
                loader: 'babel-loader',
            },
        ],
    },
    plugins: [
        new HtmlWebpackPlugin({ template: './src/index.html' }),
        new UseminWebpackPlugin({
			entries: [
				{
					path: "node_modules/p5/lib",
					fileName: "p5"
                },
				{
					path: "node_modules/sockjs-client/dist",
					fileName: "sockjs"
				}                
			]
		}),        
        new webpack.ProgressPlugin(),
    ],
};

Todo Items

  • add tests
  • switch to Typescript for better options handling
  • add more option properties