Reputation: 8103
So, I know there are a lot of similar questions here, I read all, as well as several web articles. Still, I cannot find a solution. I simply want to import es modules from lodash. Currently using rollup via codekit app.
Simply doing one of the following, will always end up in an empty js file:
import each from 'lodash-es';
import { each } from 'lodash-es';
import each from 'lodash-es/forEach';
import each from 'node_modules/lodash-es';
They all will end with the empty (currently compiling in iife):
(function () {
'use strict';
})();
Why?
Upvotes: 0
Views: 1117
Reputation: 26873
If the function isn't used in the code in any way, it will get stripped from the production output due to a process called tree shaking. It's an optimization that looks at code imports and then eliminates any unused code as a result.
It turns out that was the case here as each
wasn't used and it was imported only.
Upvotes: 4