Skip to content
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

reference static assets doesn't work #108

Closed
g13ydson opened this issue Apr 8, 2022 · 2 comments
Closed

reference static assets doesn't work #108

g13ydson opened this issue Apr 8, 2022 · 2 comments

Comments

@g13ydson
Copy link

g13ydson commented Apr 8, 2022

About PR #58 @, I would like to use Esbuild for all our static assets instead of using a different solution for images.
I tried what is in the README, but it also generates .js/.css files in the output directory.

our script:

package.json

"scripts": {
  "build:js": "esbuild app/javascript/*.* --bundle --loader:.png=file --outdir=app/assets/builds/ --public-path=assets",
  "build:css": "sass app/stylesheets/application.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules"
}

javascript/application.js

// Entry point for the build script in your package.json
import "@hotwired/turbo-rails"
import "./controllers"
import * as bootstrap from "bootstrap"

There is an image in: javascript/images/logo.png

Is there a step I'm missing so that the image is copied to the output directory?

@richardkmiller
Copy link
Contributor

richardkmiller commented Apr 8, 2022

Hi @g13ydson, your esbuild command looks correct. Esbuild won't output files that aren't imported and used in the JS, so maybe that's the cause of this issue?

You could try adding this to your javascript/application.js:

import Logo from './images/logo.png'
...
console.log(Logo)

Then when esbuild runs, the file should be copied and you'll see a line of output like this:

app/assets/builds/logo-5SRKKTLZ.png         308.3kb

Let me know if that doesn't fix it.

@g13ydson
Copy link
Author

g13ydson commented Apr 8, 2022

It worked perfectly. Thanks @richardkmiller

@g13ydson g13ydson closed this as completed Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants