tmeasday / storybook-skeleton

3 stars 1 forks source link

Try using a globbed entry plugin rather than `require.context` #4

Closed tmeasday closed 3 years ago

tmeasday commented 3 years ago

I'm actually not sure there is a big problem with using require.context() (see snowpack example) but open to ideas here if it helps.

bebraw commented 3 years ago

I would skip this one since you found a good solution already with import() as that's standard.

tmeasday commented 3 years ago

Is there a way to tell webpack about every file you might dynamically import ahead of time?

The way that code works is we do:

import data from 'path/to/stories.json';

// later
await import(data[someStoryId].parameters.filename)

I think webpack might not even allow that?

We'll be generating the json data, possibly in a separate process, possibly with webpack, IDK.

In Snowpack the above was fine because as a ESM bundler it just serves up any filename as you request it. I'm not quite sure what it would do if you tried to build a production bundle/set of bundles though. I suppose it would have the same problem.

bebraw commented 3 years ago

It cannot be completely dynamic but partially (similar to require.context). I have an example at https://survivejs.com/webpack/techniques/dynamic-loading/#dynamic-paths-with-a-dynamic-import .

On 21. May 2021, at 11.14, Tom Coleman @.***> wrote:

 Is there a way to tell webpack about every file you might dynamically import ahead of time?

The way that code works is we do:

import data from 'path/to/stories.json';

// later await import(data[someStoryId].parameters.filename) We'll be generating the json data, possibly in a separate process, possibly with webpack, IDK.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub, or unsubscribe.

tmeasday commented 3 years ago

Let's close this in favour of https://github.com/tmeasday/storybook-skeleton/issues/19