question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better dynamic pathing

See original GitHub issue

We have a large app with many components, and would like to create a directory for each one.

Something like /components/hero/index.js or /components/hero/hero.js (preferred)

Unfortunately when we run something like the following:

const UniversalComponent = universal((props) => {
  return import(`src/components/${props.type}/${props.type}`)
});

webpack names the chunk src/components/hero-hero, so ssr breaks. I saw a related issue about this, and it seems to be an issue on webpack’s side - (https://github.com/webpack/webpack/issues/5575)

Currently, because our folder structure will be consistent, we are thinking of changing the line you referenced in the webpack issue (https://github.com/faceyspacey/webpack-flush-chunks/blob/master/src/flushChunks.js#L206):

const chunk = assets[chunkName] || assets[chunkName + '-']

to something like:

// replace last instance of `/` with a `-`
// (not actual implementation. just base example)
chunkName = chunkName.replace(/\/([^/]*)$/,'-'+'$1');
const chunk = assets[chunkName] || assets[chunkName + '-']

while this works, we realize how janky it is and don’t want to rely on it.

Is there any way we can accomplish a more organized app architecture with each dynamic component being housed in its own directory?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
faceyspaceycommented, Aug 30, 2017

bingo. i know, i hate those extra files too, but it’s basically the only way to avoid creating unnecessary chunks.

now that said, i havent done it, but u may be able to use the context-replacement plugin to tell webpack to skip some files:

https://webpack.js.org/plugins/context-replacement-plugin/

just a thought if u too are annoyed by the extra files.

2reactions
shomanishikawacommented, Aug 30, 2017

Thanks so much for the response!

I’ve tried to follow your advice - I’ve kept my folder structure the same, so I have src/components/hero/hero.js, src/components/threeup/threeup.js, etc.

From there, i’ve created an src/components/async/ directory with files like src/components/async/hero.js, etc.

My async/hero.js file simply imports the actual component files, and exports it like so:

// this is the entire file
export {default} from 'src/components/hero/hero';

That way, my universal import will be something like the following:

const UniversalComponent = universal((props) => {
  return import(`src/components/async/${props.type}`)
});

This is working functionally, and just want to make sure it is in line with what you were suggesting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic channel path management - IBM
Dynamic channel path management lets workload management dynamically move channel paths through the ESCON Director from one I/O control unit to another, in ......
Read more >
Optimizing Brains and Bodies
Get started on improving energy & mental clarity: Virtual appointments with Dr. Allott · Dynamic Paths logo A8.jpg · Resources for Individuals.
Read more >
Dynamic path problems - html - Stack Overflow
Live environment: www.SomePath.com/Images/pic.jpg (Error - file path incorrect). html · dynamic · path · Share.
Read more >
MPIO and SDDDSM dynamic pathing
When you use SDDDSM for multipathing, you must use the Storport Miniport driver for ... MPIO supports dynamic pathing when you add more...
Read more >
Next.js Linking to dynamic paths - GeeksforGeeks
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found