Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

common-shakeify

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

common-shakeify - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

8

index.js

@@ -7,2 +7,3 @@ 'use strict'

const through = require('through2')
const convertSourceMap = require('convert-source-map')

@@ -127,3 +128,8 @@ const kDuplicates = Symbol('duplicates')

row.source = string.toString()
const transformed = string.toString()
if (b._options.debug) {
row.source = transformed + '\n' + convertSourceMap.fromObject(string.map).toComment()
} else {
row.source = transformed
}

@@ -130,0 +136,0 @@ this.push(row)

9

package.json
{
"name": "common-shakeify",
"version": "0.3.2",
"version": "0.4.0",
"description": "browserify tree shaking plugin using @indutny common-shake",

@@ -26,12 +26,15 @@ "main": "index.js",

"common-shake": "^2.0.2",
"convert-source-map": "^1.5.0",
"through2": "^2.0.3",
"transform-ast": "^2.1.0",
"transform-ast": "^2.2.1",
"wrap-comment": "^1.0.0"
},
"devDependencies": {
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babelify": "^7.3.0",
"browserify": "^14.4.0",
"concat-stream": "^1.6.0",
"tape": "^4.8.0",
"uglify-js": "^3.0.28"
"uglify-js": "^3.1.3"
}
}

@@ -6,2 +6,27 @@ # common-shakeify

Comments out unused exports from CommonJS modules.
With input files:
```js
// math.js
exports.min = function (a, b) { return a < b ? a : b }
exports.max = function (a, b) { return a < b ? b : a }
// app.js
var math = require('./math')
console.log(math.max(10, 20))
```
This plugin will rewrite the files to:
```js
// math.js
/* common-shake removed: exports.min = */ void function (a, b) { return a < b ? a : b }
exports.max = function (a, b) { return a < b ? b : a }
// app.js
var math = require('./math')
console.log(math.max(10, 20))
```
Use a minifier on the output to remove the exports entirely.

@@ -35,9 +60,11 @@

// Minify & save
var concat = require('concat-stream')
var uglify = require('uglify-js')
b.pipe(concat(function (source) {
fs.writeFileSync('bundle.min.js', uglify.minify(source.toString(), { compress: true }).code)
}))
var uglify = require('minify-stream')
b
.pipe(uglify())
.pipe(fs.createWriteStream('bundle.min.js'))
```
Note that using a minifier transform like uglifyify doesn't eliminate the commented-out exports.
Transforms run _before_ common-shakeify, so you have to use a minifier on the final bundle to remove the unused exports.
## Options

@@ -44,0 +71,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc