-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Add a mention for how to glob image files (frontend bundler) #428
Comments
I managed to fix this for my site by adding copy-webpack-plugin: // webpack.config.js
const path = require("path");
const { merge } = require('webpack-merge')
const CopyPlugin = require("copy-webpack-plugin");
let config = require("./config/webpack.defaults.js")
const customConfig = {
plugins: [
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, "frontend/**/*.{png,svg,jpg,jpeg,gif}"),
to: "../images/[name].[contenthash][ext]"
},
],
}),
],
};
config = merge(config, customConfig)
module.exports = config |
Thanks @matiaskorhonen, I think your CopyPlugin idea is pretty cool. I've also seen code that you can add to your entrypoint that loops over files and requires them, thus adding them to the manifest. Wonder which approach is better… |
Updating this issue to cover adding a mention for how to glob image files in both esbuild and Webpack frontend bundler configs. |
Speaking of the frontend developer, this can also be used with videos too? Not just images. Thanks for the quick fix @matiaskorhonen, looks like that should work for me as well. I'd always had issues using the frontend bundler with images, only got it work correctly with CSS/SCSS. |
Yeah, I don't see why not. You'd just need to add I used the same setup for both images and data files on the @euruko 2022 conference site: https://github.com/euruko/2022.euruko.org/blob/2496dfb206b5c6835bc82e0d7981a786fb89169e/webpack.config.js#L27-L43 |
I seem to have issues with this as I work wit esBuild better than Webpack. I gave
Code:
|
@jaredcwhite id say a copy plugin that writes to a manifest is better. The problem with the manifests that are generated by doing import statements is that the strings get inlined into the final bundle, so you would need to make a separate assets entrypoint that you never use. Also, ESBuilds asset detection is spotty at best since the asset -> hashed asset requires some workarounds. |
Currently it seems that if you want to use
webpack_path
with an image infrontend/images/
, it's not possible if the same image isn't used in a JS or CSS file (e.g.import "../images/file.png"
infrontend/javascript/index.js
).This limitation isn't mentioned anywhere in the docs, as far as I can see.
Bridgetown Version: 0.21.5
To Reproduce
frontend/images/
<link rel="icon" type="image/png" href="{% webpack_path images/favicon.png %}" />
)Current behavior
An opaque error is printed to the logs:
And the emitted mark-up is:
Expected behavior
I would expect, based on the documentation, to be able to use any image from
frontend/
with the#webpack_path
helper to take advantage of file hashes etc…Screenshots
—
Computing environment (please complete the following information):
Additional context
—
The text was updated successfully, but these errors were encountered: