lodash / babel-plugin-lodash

Modular Lodash builds without the hassle.
Other
1.96k stars 91 forks source link

Doesn't seem to be working with babel@7.x #221

Closed niftylettuce closed 6 years ago

niftylettuce commented 6 years ago

Here's my .babelrc:

{
  "presets": [
    ["@babel/env", {
      "targets": {
        "node": "6.4.0"
      }
    }]
  ],
  "plugins": [ "lodash" ],
  "sourceMaps": "inline"
}

Here's an example file:

const _ = require('lodash');

const foo = _.isString('hello world');
console.log('foo', foo);

I'd expect it to be like this after running through with babel, but it's not:

const isString = require('lodash/isString');

const foo = isString('hello world');
console.log('foo', foo);

Any idea why? I'm on babel 7x. and all my packages use @babel/xyz org.

jdalton commented 6 years ago

Hi @niftylettuce!

This plugin transforms ES6 import syntax. See the usage example.

niftylettuce commented 6 years ago

Ah, thanks @jdalton didn't know it was specific for ES. I'm not sure if you know of an alternative for require other than just doing it manual?

jdalton commented 6 years ago

There may be a transform out there on npmjs.com.

niftylettuce commented 6 years ago

I wasn't able to find one - is it not easy to add support for it in this package?

jdalton commented 6 years ago

I had better luck: lebab, replace-require-with-import, require-to-import.

I've used lebab before :D

niftylettuce commented 6 years ago

I was trying to find something that simply just worked for require without having to transform to import 😢