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

webpack-cascade-optimizer-plugin

v1.0.5

Published

A Webpack plugin that distributes common code along output files on a First-come, First-served basis.

Downloads

975

Readme

webpack-cascade-optimizer-plugin

A Webpack plugin that distributes common code along output files on a First-come, First-served basis.

This simple Webpack plugin allows you to get splitChunksPlugin's optimizations without splitting!

NOTE:

  • This plugin may be necessary only for some projects with a particular structure.

  • This plugin is intended to be used in the case of an entry object configuration. (SEE Usage)

  • I just wanted to share this with people who may need it as I did.

  • Obviously, functionality and customization should be extended in future releases. First release is basic.

Why?

Generally, Webpack splitChunksPlugin does a very good job finding out common modules along generated chunks, but gives us little control on how those common modules should be distributed.

Our options are practically limited to creating one or more chunks where common modules will be placed, but if we wanted to go beyond that, especially in a multiple entry setup (using an entry object) things can get complicated very fast.

The following example of what webpack-cascade-optimizer-plugin does should be self-explanatory:

/*

    ENTRY FILES:

        - fileA.js
            - fileAUniqueContent
            - dep1.js
            - dep3.js
            - dep4.js
            
        - fileB.js
            - fileBUniqueContent
            - dep1.js
            - dep2.js
            - dep3.js
            - dep5.js
        
        - fileC.js
            - fileCUniqueContent
            - dep1.js
            - dep3.js
            - dep4.js
            - dep5.js
        
        
    OUTPUT FILES:
    
        WITH webpack-cascade-optimizer-plugin
        
        - fileA.js
            - runtime
            - fileAUniqueContent
            - dep1.js
            - dep3.js
            - dep4.js
            
        - fileB.js
            - fileBUniqueContent
            - dep2.js
            - dep5.js
        
        - fileC.js
            - fileCUniqueContent
            
            
        WITH splitChunksPlugin ALONE (USING AN AGGRESSIVE CONFIGURATION)
        
        - fileA.js
            - fileAUniqueContent
            
        - fileB.js
            - fileBUniqueContent
        
        - fileC.js
            - fileCUniqueContent
            
        - vendors~fileA~fileB~fileC
            - dep1.js
            - dep3.js
       
        - vendors~fileA~fileC
            - dep4.js
            
        - vendors~fileB~fileC
            - dep5.js
            
        - vendors~fileB
            - dep2.js
            
        - runtime.js
        
 */

This is especially useful if you are loading your files in a sequence (fileA.js -> fileB.js -> fileC.js) and you want your code to be usable before all files are loaded. Successive files will reuse modules already loaded by previous files!

Install

npm install webpack-cascade-optimizer-plugin --save-dev

Usage

const CascadeOptimizer = require('webpack-cascade-optimizer-plugin');
// webpack.config.js

{
    [...]
    entry: {
        fileA: 'path/to/fileA.js',
        fileB: 'path/to/fileB.js',
        fileC: 'path/to/fileC.js',
    },
    output: {
        filename: '[name].js',
        path: 'output/path'
    },
    plugins: [
        new CascadeOptimizer({
            fileOrder: ['fileA, 'fileB', 'fileC', '[...]']
        })
    ]
    [...]
}

No additional configuration needed!

This plugin will override the following properties in Webpack configuration:

  • chunks, name, automaticNameDelimiter and cacheGroups in optimization.splitChunks

  • runtimeChunk in optimization

Runtime will be included only once in the first file of fileOrder array.

Options

fileOrder [array] required

Array of files names in the order in which the plugin should prioritize common code distribution.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the ISC License - see the LICENSE.md file for details

Acknowledgments

  • Webpack splitChunksPlugin
  • Webpack removeEmptyChunksPlugin