-
Notifications
You must be signed in to change notification settings - Fork 147
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
Can't load images in JavaScript files #76
Comments
@cirdes PR #58 should be helpful to you. The short answer is to open |
@cirdes Realizing too, you probably need step 2 from the PR, which is, in your case, to add |
@richardkmiller , I'm planing to move for esbuild but as first step I just replace webpacker for jsbundling. webpack.config.js
Webpack moves everything to "app/assets/builds" as expected but |
This is what is happening with my my JS component is resolving the image as |
Ah I see what you mean. I'm not sure about this, but you may be able to make it work by removing the keyword These might help: https://stackoverflow.com/questions/45809887/webpack-disable-hashing-of-image-name-on-output https://guides.rubyonrails.org/asset_pipeline.html#javascript-coffeescript-and-erb (section 2.3.3) |
Same problem here. For example, |
Same general problem, but with rails 7.0 + propshaft + jsbundling + esbuild, specifically with react-leaflet. Using Edit: Digging a little deeper into the esbuild config, I got this to work by using the |
See: https://github.com/rails/propshaft#bypassing-the-digest-step Looks like there is bug in the above 'bypassing the digest step' feature for both propshaft and sprockets. This is the issue for sprockets: This will fix it for sprockets: It has already been fixed for propshaft: |
@giedomak , thanks for pointing out this PRs. Hope rails/sprockets#726 could be merged soon. |
Wanted to comment back a solution to folks that are using JSB-Rails + Webpack 5 not ESBuild — specifically in my case how to setup Webpack to output the {
test: /\.(png|jpe?g|gif|eot|woff2|woff|ttf|svg)$/i,
type: 'asset/resource',
generator: {
filename: '[name]-[hash].digested[ext][query]' // Setup asset filename so Propshaft doesn't re-digest
}
}, That helped fix things for us. |
@jon-sully , It's working with JSB-Rails + Webpack 5! I'm using webpack with this config and now sprockets are not re-stamping the assets. Also you need sprockets >4.0.3 -> https://github.com/rails/sprockets/blob/master/CHANGELOG.md
|
Nice 👍 yeah same premise using |
@richardkmiller, moving forward to JSB-Rails with Esbuild I had to point sprockets to rails/sprockets#726 and use --public-path=/assets Images assets were working but not using my CDN to serve the assets. So I came with this solution: "--public-path=$CDN_URL_FULL/assets"
I'm not sure if esbuild should generate assets string with cdn domain or if sprockets should somehow be responsible to rewrite urls with CND. any thoughts about that? |
@cirdes If it were my decision, I guess I might leave this as a post-install configuration step. For example, the README explains how to use |
I'm having a similar, but maybe slightly different problem. After upgrading from Rails 6 and switching from Webpack to esbuild, I can load images in development, but not after deploying to production (Heroku). In production, it looks like an additional fingerprint is added to the asset path.
My esbuild.config.js looks like this: const path = require("path")
const vuePlugin = require("esbuild-vue")
require("esbuild").build({
entryPoints: ["application.js", "compartment.js"],
bundle: true,
loader: {".png": "file"},
outdir: path.join(process.cwd(), "app/assets/builds"),
absWorkingDir: path.join(process.cwd(), "app/javascript"),
publicPath: "/assets",
assetNames: "[name]-[hash].digested",
watch: process.argv.includes("--watch"),
plugins: [vuePlugin()],
}).catch(() => process.exit(1)) |
@andrewhavens Are you on Sprockets? The digest skip feature os only available on master. There are no released versions with it yet. |
Also had a bunch of issue in rails 6 + sprocket + webpack with external files and code splitting due to the re-stamping . So we decided to bypass all the asset management of rails and relying only on webpack by outputting webpack directly to output: {
....
path: 'public/js'
}, and stamping by ourselves the application.js. That might not be the rail's flavor, it gives us the control and flexibility we needed on webpack and it works very well for us and saves us a lot of headaches until a better solution arises |
Confirming that @ioev 's suggestion of |
A note for people hitting the same problem as me: Your asset name must have a dash before the digest. The default value for After changing the option to |
…/issues/76\#issue-1115571908 Better explained in a later comment https://github.com/rails/jsbundling-rails/issues/76\#issuecomment-1022695521 And I'm trying this solution https://github.com/rails/jsbundling-rails/issues/76\#issuecomment-1051248565 I would have said the solution makes not only images, but also .js and .css lose the fingerprint functionality, but for whatever reason it's still fingerptinting everything except images..
Hi,
I'm trying to migrate my Rails + React application from Webpacker to Jsbundling + Esbuild following switch_from_webpacker guide to first replace webpacker for Jsbundling
Everything is bundled to "app/assets/builds" by webpack, images included.
application.js and application.css are working fine in application.html.erb but the images in jsx files aren't loading.
My React component are trying to load "0bdd8103a525a17c3528e4f40d701b33.svg" the same as output in assets/builds folder but public/assets has the digested version of my svg "0bdd8103a525a17c3528e4f40d701b33-b8fb0ca2943e7724f64b3717f8a3e2b3ecb321adac1053107f2c89142efffd17.svg"
I'm not sure if the correct approach is to move all assets from assets/build to public/asssets with a rake or if it is possible to skip sprockets-rails digest for images and rely on webpack digested file or if there is another way to load imagens inside js files
Thanks for jsbundling effort!
The text was updated successfully, but these errors were encountered: