find-used-lodash

Use esprima to find and detect used lodash packages

Usage no npm install needed!

<script type="module">
  import findUsedLodash from 'https://cdn.skypack.dev/find-used-lodash';
</script>

README

find-used-lodash

Use Esprima to find and detect used Lodash packages

NPM Version NPM Downloads Build Status

Useful for preparing an array to pass to a build task in order to build only used packages.

Important notice Chained Lodash packages are currently not detected.

Install

npm install --save-dev find-used-lodash

Example

General Usage

var findUsedLodash = require('find-used-lodash');

console.log(findUsedLodash('_.each(["a", "b"], doSomething)');
//=> ['each']

Use in a build task (grunt,gulp)...

var findUsedLodash = require('find-used-lodash');

var fileContents = fs.readFileSync('targetFile.js', 'utf8'); //or get it from file stream
var results = findUsedLodash(fileContents);

var commaResults = results.join(',');

//then execute lodash command line with **lodash include=commaResults**

Options

@param {String} jsFileContents - the js file contents as a string
@return {String[]} array of used Lodash packages.

License

MIT @Gilad Peleg