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

disable-tree-shaking-for-chunk-plugin

v2.0.0

Published

This plugin for Webpack can disable tree shaking for all modules contained in a specific chunk. It is intended to help improve long-term caching and code reuse between project installations and builds.

Downloads

748

Readme

Disable Tree Shaking For Chunk Plugin

GitHub license Build Status npm version

This plugin for Webpack 5 can disable tree shaking for all modules contained in specified chunks. It is intended to help improve long-term caching and code reuse between project installations and builds.

Installation

This is a Node.js module available through the npm registry. Node 8 and Webpack 4.38 or higher are required.

Installation is done using the npm install command:

$ npm install --save-dev disable-tree-shaking-for-chunk-plugin

Once installed the plugin can be added to your Webpack plugins configuration:

const DisableTreeShakingForChunk = require('disable-tree-shaking-for-chunk-plugin')

module.exports = {
  //...
  plugins: [
    new DisableTreeShakingForChunk({
      test: 'chunk-name'
    })
  ]
}

Options

test (string, RegExp, Function, Array, Set)

Matches the chunk name. It may be a string matched with strict equality, a regular expression for more complex string matching, a function which will receive the chunk name as an argument and should return a boolean, or an array or set of strings.

Example

Below demonstrates part of a Webpack configuration file which sets up code splitting for a project. It has one cache group defined which will create a separate chunk for each package defined in the array.

const DisableTreeShakingForChunk = require('disable-tree-shaking-for-chunk-plugin')

const commonLibraries = ['react', 'redux', 'regenerator-runtime']

module.exports = {
  optimization: {
    splitChunks: {
      cacheGroups: {
        commonLibraries: {
          test(module) {
            const packageName = getPackageName(module.context)
            return packageName ? commonLibraries.includes(packageName) : false
          },
          name(module) {
            return getPackageName(module.context)
          }
        }
      }
    }
  },
  plugins: [
    new DisableTreeShakingForChunk({
      test: commonLibraries
    })
  ]
}

Motivation

By default when running Webpack in production mode it will try to track the properties exported by JavaScript modules and flag when the module is imported and which of those properties is used. It's this clever tracking of "used exports" that enables tree shaking by "pruning" any unused properties. Usually, this is a useful feature as it enables us to ship less code to our users but for cases where we'd like our compiled code to be cached for a long time or be reused by separate applications we need to disable it because how the module may be used over time and by different apps is unknown.

Prior Art

This plugin is based upon Webpack's internal FlagInitialModulesAsUsedPlugin by Tobias Koppers.

Development

This project uses Prettier for automatic code formatting and is tested with Jasmine.

License

This package is MIT licensed.