disable-tree-shaking-for-chunk-plugin
Advanced tools
Comparing version 1.2.0 to 2.0.0
{ | ||
"name": "disable-tree-shaking-for-chunk-plugin", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "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.", | ||
@@ -9,6 +9,8 @@ "main": "src/plugin.js", | ||
"test": "npm run lint && jasmine test/*.test.js", | ||
"webpack": "[ -d test/temp ] && rm -r test/temp; node test.js" | ||
"webpack": "[ -d test/temp ] && rm -r test/temp; node test.js", | ||
"preinstall": "[ \"$INIT_CWD\" != \"$PWD\" ] || npm_config_yes=true npx check-engine" | ||
}, | ||
"engines": { | ||
"node": ">= 8.0.0" | ||
"node": "12.x", | ||
"npm": "7.x || 8.x" | ||
}, | ||
@@ -20,16 +22,24 @@ "keywords": [ | ||
"devDependencies": { | ||
"check-engine": "^1.10.1", | ||
"jasmine": "^3.5.0", | ||
"prettier": "^2.0.0", | ||
"webpack": "^4.41.0" | ||
"webpack": "^5.64.4" | ||
}, | ||
"peerDependencies": { | ||
"webpack": "^4.38.0" | ||
"webpack": "5.x" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:i-like-robots/disable-tree-shaking-for-chunk-plugin.git" | ||
"url": "git@github.com:Financial-Times/disable-tree-shaking-for-chunk-plugin.git" | ||
}, | ||
"homepage": "https://github.com/i-like-robots/disable-tree-shaking-for-chunk-plugin", | ||
"author": "Matt Hinchliffe", | ||
"license": "MIT" | ||
"homepage": "https://github.com/Financial-Times/disable-tree-shaking-for-chunk-plugin", | ||
"contributors": [ | ||
"Matt Hinchliffe", | ||
"Financial Times" | ||
], | ||
"license": "MIT", | ||
"volta": { | ||
"node": "12.22.9", | ||
"npm": "8.3.1" | ||
} | ||
} |
# Disable Tree Shaking For Chunk Plugin | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/i-like-robots/disable-tree-shaking-for-chunk-plugin/blob/master/LICENSE) [![Build Status](https://travis-ci.org/i-like-robots/disable-tree-shaking-for-chunk-plugin.svg?branch=master)](https://travis-ci.org/i-like-robots/disable-tree-shaking-for-chunk-plugin) [![npm version](https://img.shields.io/npm/v/disable-tree-shaking-for-chunk-plugin.svg?style=flat)](https://www.npmjs.com/package/disable-tree-shaking-for-chunk-plugin) [![Greenkeeper badge](https://badges.greenkeeper.io/i-like-robots/disable-tree-shaking-for-chunk-plugin.svg)](https://greenkeeper.io/) | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Financial-Times/disable-tree-shaking-for-chunk-plugin/blob/main/LICENSE) [![Build Status](https://circleci.com/gh/Financial-Times/disable-tree-shaking-for-chunk-plugin.svg)](https://app.circleci.com/pipelines/github/Financial-Times/disable-tree-shaking-for-chunk-plugin) [![npm version](https://img.shields.io/npm/v/disable-tree-shaking-for-chunk-plugin.svg?style=flat)](https://www.npmjs.com/package/disable-tree-shaking-for-chunk-plugin) | ||
This plugin for [Webpack 4] 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. | ||
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. | ||
[Webpack 4]: https://webpack.js.org/ | ||
[Webpack 5]: https://webpack.js.org/ | ||
@@ -9,0 +9,0 @@ |
@@ -1,5 +0,8 @@ | ||
module.exports = (m) => { | ||
m.used = true | ||
m.usedExports = true | ||
m.buildMeta.providedExports = true | ||
module.exports = (module, moduleGraph, runtime) => { | ||
const exportsInfo = moduleGraph.getExportsInfo(module) | ||
exportsInfo.setUsedInUnknownWay(runtime) | ||
if (module.factoryMeta === undefined) { | ||
module.factoryMeta = {} | ||
} | ||
module.factoryMeta.sideEffectFree = false | ||
} |
const ConcatenatedModule = require('webpack/lib/optimize/ConcatenatedModule') | ||
const { mergeRuntimeOwned, getEntryRuntime } = require('webpack/lib/util/runtime') | ||
const isTargetChunk = require('./isTargetChunk') | ||
@@ -18,12 +19,19 @@ const markAsUsed = require('./markAsUsed') | ||
compiler.hooks.compilation.tap(PluginName, (compilation) => { | ||
const { moduleGraph } = compilation | ||
compilation.hooks.afterOptimizeChunkModules.tap(PluginName, (chunks) => { | ||
const targetChunks = chunks.filter((chunk) => isTargetChunk(chunk.name, this.test)) | ||
const targetChunks = Array.from(chunks).filter((chunk) => | ||
isTargetChunk(chunk.name, this.test) | ||
) | ||
let runtime = undefined | ||
for (const [name, { options }] of compilation.entries) { | ||
runtime = mergeRuntimeOwned(runtime, getEntryRuntime(compilation, name, options)) | ||
} | ||
targetChunks.forEach((targetChunk) => { | ||
targetChunk.modulesIterable.forEach((m) => { | ||
if (m.type.startsWith('javascript/')) { | ||
markAsUsed(m) | ||
compilation.chunkGraph.getChunkModulesIterable(targetChunk).forEach((module) => { | ||
if (module.type.startsWith('javascript/')) { | ||
markAsUsed(module, moduleGraph, runtime) | ||
if (m instanceof ConcatenatedModule) { | ||
markAsUsed(m.rootModule) | ||
if (module instanceof ConcatenatedModule) { | ||
markAsUsed(module.rootModule, moduleGraph, runtime) | ||
} | ||
@@ -30,0 +38,0 @@ } |
Sorry, the diff of this file is not supported yet
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
NPM Shrinkwrap
Supply chain riskPackage contains a shrinkwrap file. This may allow the package to bypass normal install procedures.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
116807
28
2374
4
2
2