embroider-build / ember-auto-import

Zero config import from npm packages
Other
360 stars 109 forks source link

Does not work with babel-plugin-lodash #558

Open simonihmig opened 1 year ago

simonihmig commented 1 year ago

I was trying to use babel-plugin-lodash to get rid off the monolithic lodash.js module and instead get cherry-picked and tree-shaken individual lodash/* modules everywhere. While the babel plugin works, and indeed rewrites all the imports, I still end up having both the monolithic lodash.js as well as the individual modules:

image

I searched through the /dist output to see what is pulling this in, but there is nothing anymore depending on it. There is a d('lodash', ...) AMD shim in chunk.app.*.js, but no other define() that actually consumes this. Also putting a breakpoint in front of the actual module (the webpack emitted eval()) confirms that it is unused.

When looking at the output of BROCCOLI_DEBUG=ember-auto-import:preprocessor:* ember b, I see modules like these (some irrelevant ... parts omitted):

define("some-module, ["exports", "lodash/cloneDeep", "faker", ...], function (_exports, _cloneDeep2, _faker, ...) {
  "use strict";

  Object.defineProperty(_exports, "__esModule", {
    value: true
  });
  _exports.default = void 0;
  0; //eaimeta@70e063a35619d71f0,"lodash/cloneDeep",0,"lodash",0,"faker", ...

The original source has a import _ from 'lodash'; and somewhere else some _.cloneDeep() calls. So the babel plugin does its job obviously, but looking at that eaimeta... embedded serialization it seems eai still thinks that lodash is imported. First I thought it might be related to the execution order of babel plugins, but what puzzles me is that in that eaimeta... both lodash/cloneDeep (which must come from babel-plugin-lodash) as well as lodash are present.

Also confusing to me is the fact that the tree passed to the Analyzer (by looking at the output of BROCCOLI_DEBUG=ember-auto-import:preprocessor:*) already contains those eaimeta..., as this is the input of the Analyzer here. But maybe I am misunderstanding something...

/cc @NullVoxPopuli