nollup icon indicating copy to clipboard operation
nollup copied to clipboard

Dynamic imports

Open ajbouh opened this issue 4 years ago • 7 comments

Hi, I tried implementing a fast development loop for sapper using nollup but it seems that support for dynamic imports is not (yet?) present in nollup.

A few specific observations:

  • OutputChunk.dynamicImports is missing
  • ModuleInfo.dynamicallyImportedIds is missing
  • modules referenced by dynamic imports themselves don't seem to be included in any of the output chunks

Is this something that should be present or is there a fundamental reason it's incompatible with the nollup philosophy?

ajbouh avatar Aug 28 '20 21:08 ajbouh

Not everything has been implemented, but can't see any reason why those can't be added. Any code snippets you can share for context on what you're trying to do? 🙂

PepsRyuu avatar Aug 28 '20 21:08 PepsRyuu

This is an example of a use of ModuleInfo.dynamicallyImportedIds.

https://github.com/metered/sapper/commit/15cde73df542a1bbf5524e71325df51521fe7e34#diff-9a33240426fe04fe7d015c7ec8e07c63R137

It's a rollup plugin port of sapper's sapper build command. In this case it's trying to generate a proper list of css stylesheets referenced by a particular javascript chunk.

I have another iteration of this rollup plugin that hasn't been pushed yet that expands on this functionality.

ajbouh avatar Aug 28 '20 23:08 ajbouh

Great! I'll hopefully have something for this soon over the next few days!

PepsRyuu avatar Aug 29 '20 14:08 PepsRyuu

https://github.com/PepsRyuu/nollup/pull/142 Does this help to address the use case? :)

PepsRyuu avatar Sep 01 '20 20:09 PepsRyuu

@ajbouh Any update on this?

PepsRyuu avatar Sep 11 '20 20:09 PepsRyuu

Hi @PepsRyuu, just circled back to this. Doing an install directly from that PR gives me the following error:

ParseError: /node_modules/@apollo/client/core/ApolloClient.js
TypeError: Cannot read property 'length' of undefined
    at .../node_modules/nollup/lib/impl/utils.js:56:61
    at Array.forEach (<anonymous>)
    at prepareSourceMapChain (.../node_modules/nollup/lib/impl/utils.js:51:18)
    at combineSourceMapChainFast (.../node_modules/nollup/lib/impl/utils.js:96:34)
    at Object.transform (.../node_modules/nollup/lib/impl/PluginLifecycle.js:211:25)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at compileModule (.../node_modules/nollup/lib/impl/NollupCompiler.js:58:27)
    at compileModule (.../node_modules/nollup/lib/impl/NollupCompiler.js:120:13)
    at compileModule (.../node_modules/nollup/lib/impl/NollupCompiler.js:120:13)
    at compileModule (.../node_modules/nollup/lib/impl/NollupCompiler.js:120:13)
    at compileModule (.../node_modules/nollup/lib/impl/NollupCompiler.js:122:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

ajbouh avatar Oct 03 '20 00:10 ajbouh

Here's a gist with the contents of ApolloClient.js: https://gist.github.com/ajbouh/749dc1bcc0f66a974381b85ec2830b77

Perhaps it's because this is using import syntax even though it's a .js file?

ajbouh avatar Oct 03 '20 00:10 ajbouh