Nate-Wessel / urban-freight

Maps for a dashboard on GHG emissions from urban freight in Canadian cities
https://www.pembina.org/urban-freight
0 stars 0 forks source link

Use dynamic imports to test for data availability #74

Closed Nate-Wessel closed 2 years ago

Nate-Wessel commented 2 years ago

So, partly this will help me more easily figure out what data is available once we get into having a lot more files for the bike infra layer(s). Partly this is something I'd meant to do but hadn't yet figured out how to do at the time - and now I'm going back and doing it.

This PR switches from explicitly importing all data files at build time to importing them dynamically at run time based on the fact that we're already using consistent names and filepaths for everything. Now, if the data file at the expected path doesn't exist, we don't have it. It doesn't need to be explicitly imported/identified per-city.

Nate-Wessel commented 2 years ago

This should not really change any functionality, but does clean up the code making it easier to do other things later on. @jamaps if you could, please just check that I haven't broken anything.

Nate-Wessel commented 2 years ago

I've renamed all .topojson files to .topo.json to make clear that they're JSON and can be compiled as such by Webpack. This will save a round-trip to the server since the dynamic import will get the chunk data directly rather than importing just the chunk-name to be fetched.

This all seems to be working well, EXCEPT that now webpack is crashing for me in build-dev mode when something it's watching changes. Does it have too many files to watch? Too much JSON in memory? It builds fine the first time.

Nate-Wessel commented 2 years ago

Discussion of the problem here: https://github.com/webpack/webpack/issues/1914 No definitive solutions

Nate-Wessel commented 2 years ago

Webpack issue, perversely, is fixed now

jamaps commented 2 years ago

Glad to see that the issue fixed itself?! All looks good on Master :)

Nate-Wessel commented 2 years ago

Glad to see that the issue fixed itself?!

After ~3 hours of focused debugging, it fixed itself ;-)

https://github.com/webpack/webpack/issues/15789