How to Import a Single Lodash Function?

后端 未结 7 1766
無奈伤痛
無奈伤痛 2020-11-30 19:42

Using webpack, I\'m trying to import isEqual since lodash seems to be importing everything. I\'ve tried doing the following with no success:

imp         


        
7条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 20:08

    Not related to webpack but I'll add it here as a lot of people are currently moving to typescript.

    You can also import a single function from lodash using import isEqual from 'lodash/isEqual'; in typescript with the esModuleInterop flag in the compiler options (tsconfig.json)

    example

    {
      "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "lib": ["es6", "dom"],
        "moduleResolution": "node",
        "esModuleInterop": true,
        ...
      }
    }
    

提交回复
热议问题