Parcel: Use static files from dist folder

Created on 3 May 2020  路  3Comments  路  Source: parcel-bundler/parcel

馃檵 feature request

A means to import static files that need no processing.

馃拋 Possible Solution

Maybe an output dir variable (__outputDir) which Parcel converts to new relative paths during compilation. This should work in HTML, CSS and JS files.

For example, if I place say an image in dist/images/test.jpg, I should be able to use that in my index.html as something like <img src="__outputDir/images/test.jpg" /> which parcel converts to src="/images/test.jpg".

馃敠 Context

This could help in cases where Parcel needn't manually copy many files (such as images, icons etc) for larger projects, greatly reducing build time and effort.

馃捇 Examples

Webpack has similar variables I believe: https://webpack.js.org/guides/public-path/

Feature static

Most helpful comment

Say there are about 100 large image files in the project which won't be updated later on after adding to the project. In such a case, doesn't this option reduce the load for copying files each time (I'm assuming Parcel copies all these files each time I run it and that contents of dist folder isn't deleted on each run) and this also prevents bloating of the project directory by eliminating 2 copies of the same file?

All 3 comments

This could help in cases where Parcel needn't manually copy many files

In the end, you still have to "manually" copy them. So I don't see what advantage this would have.

This could be implemented using a named pipeline in Parcel 2 (e.g. raw: images/test.jpg).

Say there are about 100 large image files in the project which won't be updated later on after adding to the project. In such a case, doesn't this option reduce the load for copying files each time (I'm assuming Parcel copies all these files each time I run it and that contents of dist folder isn't deleted on each run) and this also prevents bloating of the project directory by eliminating 2 copies of the same file?

Right, static resources could be massive, such as videos, 3D models, textures, point clouds, etc. Copying them is not a solution.

Was this page helpful?
0 / 5 - 0 ratings