Exciting release!Introducing "safe npm". Learn more
Socket
Log inDemoInstall

disable-tree-shaking-for-chunk-plugin

Package Overview
Dependencies
0
Maintainers
3
Versions
5
Issues
File Explorer

Advanced tools

disable-tree-shaking-for-chunk-plugin

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.

    2.0.0latest
    GitHub

Version published
Maintainers
3
Weekly downloads
666
decreased by-1.48%

Weekly downloads

Changelog

Source

v2.0.0

What's Changed

  • Add support for Webpack 5 by @ivomurrell in https://github.com/Financial-Times/disable-tree-shaking-for-chunk-plugin/pull/6
  • Integrate plugin into FT workflow by @ivomurrell in https://github.com/Financial-Times/disable-tree-shaking-for-chunk-plugin/pull/5

Breaking Changes

  • Dropped support for Webpack 4

New Contributors

  • @ivomurrell made their first contribution in https://github.com/Financial-Times/disable-tree-shaking-for-chunk-plugin/pull/5, nice work, Ivo!

Full Changelog: https://github.com/Financial-Times/disable-tree-shaking-for-chunk-plugin/compare/v1.2.0...v2.0.0

Readme

Source

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.

Keywords

FAQs

Last updated on 17 Feb 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc