3

I have a question regarding importing, for example, join from lodash. As stated by this answerer, the way to go would be the following:

import join from 'lodash-es/join'

(File size of my dist/bundle.js after webpack --optimize-minimize: 1K)

But I'd like to import only the join function from lodash-es/lodash.js. However, this does not seem to be possible.

lodash-es/lodash.js uses this to export the library:

export { default as add } from './add.js';
export { default as after } from './after.js';
export { default as ary } from './ary.js';
export { default as assign } from './assign.js';

I've already tried:

import join from 'lodash-es'

(File size: 133K)

import { join } from 'lodash-es'

(File size : 133K)

import { join } from 'lodash-es/lodash.js'

(File size : 133K)

Apparently none of these work since the entire lib is assigned to join.

So how do I import only lodash/join from the lodash.js-file without targeting the specific file?

I am using webpack 2.5.1 and lodash-es 4.17.4

Community
  • 1
  • 1
Tom M
  • 2,815
  • 2
  • 20
  • 47
  • Doesn't `import { join } from 'lodash-es';` with `new webpack.LoaderOptionsPlugin({ minimize: true });` work? – Andrew Li May 15 '17 at 16:40
  • I added this in the `module.exports.plugins` array in my webpack.config.js but `import { join } from 'lodash-es;'` still assigns the entire library – Tom M May 15 '17 at 16:47
  • Possible duplicate of [ES6 variable import name in node.js?](https://stackoverflow.com/questions/29168433/es6-variable-import-name-in-node-js) – Paul Sweatte Jul 03 '17 at 22:22
  • @Paul Sweatte no, I'm not trying to pass a variable to `import` – Tom M Aug 11 '17 at 14:01

0 Answers0