How to use lodash at the same time with the underscore along on the same web page

To use lodash at the same time as the underscore you need to do some dirty tricks because both libraries share the same global variable _

  • Need to add lodash dependency into package.json of your module

  • run npm install ​ - to install lodash npm package

  • add to the webpack.config.js the following lines

  • In the main js file of your module add this line _.noConflict(). This line is required to restore global variable _ for underscore package to do not affect existing js code.

  • Use _lodash global variable instead of _ for call functions from lodash package
    image

  • run npm run webpack:dev ​ - to build and bundle scripts

  • enjoy :slight_smile:

1 Like