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

Add webpack loader for images #38

Open
jtbandes opened this issue Apr 29, 2022 · 3 comments
Open

Add webpack loader for images #38

jtbandes opened this issue Apr 29, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@jtbandes
Copy link
Member

jtbandes commented Apr 29, 2022

Our default webpack config is lacking loaders for images. If someone wants to import and use an image file, they get errors like this: https://github.com/foxglove/studio/discussions/3264#discussioncomment-2648824

@jtbandes jtbandes added the enhancement New feature or request label Apr 29, 2022
@rgov
Copy link
Contributor

rgov commented May 24, 2022

The simplest way to do this right now is

  1. Enable inline Asset Modules. Webpack will copy the entire contents of the file as a base64-encoded data: URL:

    config.module.rules.push({
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
        type: "asset/inline",
    });
    
  2. Add TypeScript declarations that explain that the type of an imported PNG or whatever is a string constant.

    declare module "*.png" {
        const content: string;
        export default content;
    }

That said, I have a proposed change to Studio itself that would support asset/resource instead, where the resource is instead copied into the extension's dist/ directory, and Webpack inserts the URL of the resource.

@bnbhat
Copy link

bnbhat commented Oct 28, 2024

I am trying to load a PNG file in my custom extension. Is there any fix for this issue?

edit: above mentioned answer by @rgov solved the issue for me.

@defunctzombie
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

4 participants