You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My web app has a large folder containing what are effectively scripts in custom DSLs (plus assets they refer to). At runtime my Javascript code will dynamically select an entry point (based on data it gets from an API call; the set of all available scripts is statically known at bundling time but which one will be selected is not) in this folder and start processing it, which will involve fetching many other files from the same folder tree.
Up til now I've been handling this by simply copying the folder to my deployment location (or local dist dir when running the dev server), and making sure my Javascript code references these files with a dynamic runtime string that Parcel isn't going to pick up and rewrite.
I'm now trying to upgrade my system so that these assets are deployed with some sort of hashing (not so much for caching but so as to help guarantee that a client doesn't end up loading a mix of old and new files if they happen to be loading the app when I deploy an update), so that once you've loaded an entry file it effectively determines the exact version of every other file it will transitively reference (and I can have multiple versions of this folder tree deployed alongside each other until I'm certain that nobody has a cached file referencing the older version).
My Javascript function for loading things from these custom assets already takes a parameter for a base URL to the root folder of the custom assets. So it seems to me that the nearest way to achieve my goal would be for that parameter to be a new URL(...) referring to the folder, and have Parcel copy the entire folder as a "bundle" to an output path with a hash (while retaining the unhashed names of all of the files underneath that subtree) and rewrite the URL to point to this output folder, much as it would do for a new URL(...) referencing an image or other non-code asset. The need to rewrite the URL to include the hash is what makes me think I need to integrate this into Parcel's process rather than just script it up as a pre- or post- build step.
I don't believe this is something Parcel can do out of the box, so I'm assuming I'll have to write a plugin (or several). But I'm not quire sure where this fits into Parcel's model; what sort of plugins should I be writing? Can a transformer work on an "asset" that is a folder? Do I need a resolver to make sure it doesn't try to find an index file if I supply a path to a folder? If a more experienced Parceller could outline a sketch of what plugins I would need to write, that would be a great help. (Or some other advice on how to approach this)
The other obvious alternative (and perhaps more "the Parcel way") is to actually parse my DSLs in order to make Parcel aware of the dependency tree. This seems conceptually more straightforward (I just write transformer plugins for my custom formats, right?), but it seems like it would be a lot more work. The code that parses these DSLs is part of the app I'm bundling with Parcel, so extracting that out so it can be consumed as a Parcel plugin seems difficult (the code is legacy and unfortunately very coupled to its job in the browser). But perhaps if my "copy an entire folder with a content hash" idea is also extremely difficult, then it would be worth reconsidering.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
My web app has a large folder containing what are effectively scripts in custom DSLs (plus assets they refer to). At runtime my Javascript code will dynamically select an entry point (based on data it gets from an API call; the set of all available scripts is statically known at bundling time but which one will be selected is not) in this folder and start processing it, which will involve fetching many other files from the same folder tree.
Up til now I've been handling this by simply copying the folder to my deployment location (or local
dist
dir when running the dev server), and making sure my Javascript code references these files with a dynamic runtime string that Parcel isn't going to pick up and rewrite.I'm now trying to upgrade my system so that these assets are deployed with some sort of hashing (not so much for caching but so as to help guarantee that a client doesn't end up loading a mix of old and new files if they happen to be loading the app when I deploy an update), so that once you've loaded an entry file it effectively determines the exact version of every other file it will transitively reference (and I can have multiple versions of this folder tree deployed alongside each other until I'm certain that nobody has a cached file referencing the older version).
My Javascript function for loading things from these custom assets already takes a parameter for a base URL to the root folder of the custom assets. So it seems to me that the nearest way to achieve my goal would be for that parameter to be a
new URL(...)
referring to the folder, and have Parcel copy the entire folder as a "bundle" to an output path with a hash (while retaining the unhashed names of all of the files underneath that subtree) and rewrite the URL to point to this output folder, much as it would do for anew URL(...)
referencing an image or other non-code asset. The need to rewrite the URL to include the hash is what makes me think I need to integrate this into Parcel's process rather than just script it up as a pre- or post- build step.I don't believe this is something Parcel can do out of the box, so I'm assuming I'll have to write a plugin (or several). But I'm not quire sure where this fits into Parcel's model; what sort of plugins should I be writing? Can a transformer work on an "asset" that is a folder? Do I need a resolver to make sure it doesn't try to find an index file if I supply a path to a folder? If a more experienced Parceller could outline a sketch of what plugins I would need to write, that would be a great help. (Or some other advice on how to approach this)
The other obvious alternative (and perhaps more "the Parcel way") is to actually parse my DSLs in order to make Parcel aware of the dependency tree. This seems conceptually more straightforward (I just write transformer plugins for my custom formats, right?), but it seems like it would be a lot more work. The code that parses these DSLs is part of the app I'm bundling with Parcel, so extracting that out so it can be consumed as a Parcel plugin seems difficult (the code is legacy and unfortunately very coupled to its job in the browser). But perhaps if my "copy an entire folder with a content hash" idea is also extremely difficult, then it would be worth reconsidering.
Beta Was this translation helpful? Give feedback.
All reactions