common-shakeify
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -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) |
{ | ||
"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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
101
5
13810
5
6
10
217
+ Addedconvert-source-map@^1.5.0
Updatedtransform-ast@^2.2.1