bridgetown icon indicating copy to clipboard operation
bridgetown copied to clipboard

Clarify how to reference static files on the frontend from Webpack/Esbuild

Open mtomov opened this issue 2 years ago • 1 comments

This is a 🔦 documentation change.

Summary

Provide examples for referencing static files with Esbuild and Webpack.

Context

Esbuild and Webpack have a slightly different strategy for referencing static files that are processed by them. Provide examples to ease use.

Alternatively, we can include those examples directly in the templates, optionally in a commented-out state.

Feel free to close PR if obvious or incorrect.

Thank you!

mtomov avatar Jun 11 '22 18:06 mtomov

Thanks @mtomov for the submission. Can we move this to a separate section on that page which is related to globbing multiple asset files? I personally don't ever glob-import images through the frontend bundling pipeline, so I'd want to make it clear this is an entirely optional step. Also, we wouldn't ever want to console.log anything that's not truly a debug statement. I think simply referencing the variable in a loop (maybe like images.forEach(image => image)) would suffice.

jaredcwhite avatar Jun 27 '22 15:06 jaredcwhite

@mtomov ~~Can confirm this does work for esbuild:~~

import images from "../images/**/*.{jpg,jpeg,png,svg,gif}"
images.forEach(image => image)

Actually that causes a runtime error -- this seems to work:

import images from "../images/**/*.{jpg,jpeg,png,svg,gif}"
Object.entries(images).forEach(image => image)

jaredcwhite avatar Apr 12 '23 17:04 jaredcwhite

Hi @jaredcwhite , indeed Object.entries(images).forEach(image => image) works!

mtomov avatar Apr 14 '23 11:04 mtomov

@mtomov Awesome! Do you think you could make a quick update to the PR based on my two comments above? Then I shall gladly merge! ☺️

jaredcwhite avatar Apr 20 '23 16:04 jaredcwhite

Thanks @jaredcwhite . Just updated. Sorry for the delay

mtomov avatar Jul 24 '23 10:07 mtomov