Giter Club home page Giter Club logo

Comments (8)

Araneline avatar Araneline commented on May 14, 2024 4

Hello @ShaunLWM,
I don't think it's a boilerplate problem. Rather a lack of documentation. Let's dive into the problem:

First of all, contentscript should understand that we want an image from our extension and not from a page. For that we can use the chrome.runtime.getURL() function. It looks like this:

import login from '@assets/img/login.svg'
...
<img src={chrome.runtime.getURL(login)} alt="login" />

Oops, still not working. Check the errors in chrome-extension page and discover the line saying our image should be listed under web_accessible_resources in manifest. All right, let's do it. Open the manifest.ts file in our root directory and add this:

web_accessible_resources: [
    {
      resources: [
        ...
        'assets/svg/*.svg',
    }
]

After that, reload the extension and you should see your image.

TLDR:
You want to wrap your image imports in chrome.runtime.getURL() and list the folder with images in your manifest.ts under web_accessible_resources.

P.S. Mind that if you will try to import a png or jpg, you should add something like 'assets/png/*.png' to the list of resources.

from chrome-extension-boilerplate-react-vite.

github-actions avatar github-actions commented on May 14, 2024

Thank you for your contribution. We will check and reply to you as soon as possible.

from chrome-extension-boilerplate-react-vite.

ShaunLWM avatar ShaunLWM commented on May 14, 2024

Understood. Will have a look. Thank you so much for the detailed explanation, appreciate it.

from chrome-extension-boilerplate-react-vite.

Zaniyar avatar Zaniyar commented on May 14, 2024

how about other resources like pdfs or so? I get compilation erros for those files.

[vite:build-import-analysis] Parse error @:1:34998
...
...

                                         ^
2: 7H7@ݶ��6,7���P%7l7`♥��>7�7�↨��c7�7�5�S5�5,���67���k6�6�8��6►7���8↔7d7��1�2@�7�7 L�ئ7�7 ����7�7Ё�@�6.7�Ŷ�+7r7��↑7R7@��x7�7�F��Z7�7�,���6(7���`�7��� �6�6�z���67��� �6$7��0     7:7�Ͷ�*7h7♥�@�6↑7����6�6A���6�6]�@k6�61���6�6�����6�6�I���6�6s���6♦7���8�7�7p��H�7�7�v��47p7�♠��7<7Ѷ�j7�7�3��97r7 ♣� �7�7�<��7�7@m��♣7.7@����7�70��y7�7�,���7�*8�·<�7�79���7§8`��P�6∟7����4�4��  5`5д4��►6H6۵��5 6���$6h6�v5�5:�05@���5�5�����4�����������A6�6� n6�6�/���506���J6�6§��4�2`§6X6۵��6�6�F�►�6�6i��6�6�D�`�6�6t���43��22[8@�8(♣���7�8►�6@6ѵ�[6�6$��W6�6!��46p6��@
3: 686ϵ�26�6♣�@-6h6☻��)6`6���!6X6�@R6�6∟�@M6�6↑���6�6�a�@�6�6l� �6�6D��6�6�>��6�6�����67�����6�6C�@6�6���6�6X��w6�6�7��d6�6*��6�6�a�Ч6�6x��K6�6�▬�@26x6�♦��m6�60�p4�4P��4�4h��45H��4�4h��4�4���45p��45H��4�4H��45X�P4�4@��45���4@5��j4�4@��45��x4�4@�Z4�4↑�v4�48��4 5���4�4h��45`��45h��4�4H��4�4p�<45�d4�4P�X4�4 F7@ն��67���►�6
transforming (4259) node_modules\lodash\_hashDelete.js
index.js:38     GET chrome-extension://bcjighfjikochhpeopamggdmdjcbfdid/assets/js/index.js net::ERR_FILE_NOT_FOUND
dynamicImport @ index.js:38
(anonymous) @ index.js:39
preload @ index.js:8
(anonymous) @ index.js:37
Show 4 more frames
Show less
/:1 Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: chrome-extension://bcjighfjikochhpeopamggdmdjcbfdid/assets/js/index.js

from chrome-extension-boilerplate-react-vite.

Jonghakseo avatar Jonghakseo commented on May 14, 2024

@Zaniyar

Have you added the PDF extension to your resources?

from chrome-extension-boilerplate-react-vite.

Zaniyar avatar Zaniyar commented on May 14, 2024

@Jonghakseo I ended up using the vite plugin-url https://www.npmjs.com/package/@rollup/plugin-url to load binary files

from chrome-extension-boilerplate-react-vite.

Jonghakseo avatar Jonghakseo commented on May 14, 2024

@all-contributors please add @Araneline for question

from chrome-extension-boilerplate-react-vite.

allcontributors avatar allcontributors commented on May 14, 2024

@Jonghakseo

I've put up a pull request to add @Araneline! 🎉

from chrome-extension-boilerplate-react-vite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.