lodash (4.17.15) as a Lightning Web Component
- Copy the
force-app/main/default/lwc/lodash
directory into your org and deploy. - Import lodash functions in your components and use as normal!
import {LightningElement} from 'lwc';
import {sortBy, groupBy, isNil} from 'c/lodash';
export default class MyComponent extends LightningElement {
// use sortBy, groupBy, isNil...
}
- Run the following command with the lodash CLI:
lodash modularize exports=es -o ./
- Rename all default files from
<filename>.default.js
to<filename>Default.js
, updating imports in each file appropriately. The component will fail to compile if a filename contains multiple.
s—although not explicitly stated in the documentation, it seems that filenames have the same restrictions as directory names (excluding the extension). - Create a new
modules
directory and move all files exceptlodash.js
andlodashDefault.js
into it, renaming imports in each file appropriately.
- Script the build process
- Include
lodash/fp
modules