Is there any way to avoid importing the whole library and import only a function or partial of it?
For example with lodash you can do something like this: import has from 'lodash/has';
Example would be:
import moment from 'moment';
moment.months()
I know the latest webpack can handle it automatically, but question is for old webpack (1.0)
Is there any way to avoid importing the whole library and import only a function or partial of it?
For example with lodash you can do something like this: import has from 'lodash/has';
Example would be:
import moment from 'moment';
moment.months()
I know the latest webpack can handle it automatically, but question is for old webpack (1.0)
import { months } from 'moment'
– Surya Purohit
Commented
Apr 1, 2017 at 12:39
lodash.*
packages). Moment wasn't. You will have the whole library in your bundle any way.
– Estus Flask
Commented
Apr 1, 2017 at 12:55
default
export like that in ES6 module. In order for them to be accessed , they should be named exports, export months ...
(and they aren't). The code you've shown works just because it falls back to CJS module - and the way it works always depends on how build tool was configured. And also, it is not possible to tree-shake anything from CJS modules.
– Estus Flask
Commented
Apr 1, 2017 at 13:17
It's impossible for moment.. You can do some plugin: https://github./moment/moment/issues/2373