10:34
<Jack Works>

How do you think about this:

A new proposal that allows to partially download the module graph. This enables link-time tree shake for ESModule.

// some-package/index.js
export { a } from './a.js'
export { b } from './b.js'

// main.js
partial import { a } from 'some-package'

Only some-package/a.js will be downloaded. To make this possible, some requirements are applied.

  • If the file contains export * from './x.js', to make it correctly resolved, ./x.js will still be downloaded, which means, if you want your module can be imported partially, you'd better to write all export names instead of use export * from which might be annoying for library authors.
  • A partially imported file might be failed to import in the future because download may fail. import('some-package') fails if ./b.js is not found.

This proposal has the same design problem that @yulia's defer import faces (e.g. mixed usage of normal import and defer/partial import).

21:18
<ljharb>
that seems like a lot of complexity to add, compared to import a from 'some-package/a.js'
21:18
<ljharb>
iow, it seems like the need to do a partial import is solely caused by having created a file that re-exports (as opposed to forcing/encouraging deep importing)