Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: import lodash modules explicitly, vs _ import #830

Closed
cdaringe opened this issue Nov 10, 2016 · 5 comments
Closed

RFC: import lodash modules explicitly, vs _ import #830

cdaringe opened this issue Nov 10, 2016 · 5 comments
Labels

Comments

@cdaringe
Copy link
Contributor

problem statement

current implementations do:

import _ from lodash

this means that at bundle time, all of lodash gets included

solution

use fn-specific imports

import get from 'lodash/get'
import uniq from 'lodash/uniq'

bundle sizes will now be small!

@levithomason
Copy link
Member

We have this done automatically by babel using https://github.com/lodash/babel-plugin-lodash. Compare the src and dist directories to see it in action.

@cdaringe
Copy link
Contributor Author

WAT! get out of town! Cool :)

@levithomason
Copy link
Member

Very cool, even more cool is you can pass { id: semantic-ui-react } to it and it will do the same thing for your bundles of our package.

You can follow this and more optimization work in #731.

@mmueller1589
Copy link

I tried the babel plugin lodash. This is the .balerc part:

"plugins": [
    ["lodash", { "id": "semantic-ui-react" }]
]

Unfortunately my imports do not work anymore after that.

Error running template: ReferenceError: Grid is not defined
    at SearchPage.render (imports/scenes/Start/SearchPage.jsx:41:7)

I do the imports per module like this:

import Grid from 'semantic-ui-react/dist/commonjs/collections/Grid';

Any idea what might be the issue?

@layershifter
Copy link
Member

If you're using babel-plugin-lodash, you need to use usual imports import { Grid } from 'semantic-ui-react'. If you're using Webpack 4, you don't need it at all, tree shaking is working.

Please Do Not Necropost!

@Semantic-Org Semantic-Org locked as resolved and limited conversation to collaborators Mar 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants