aklinker1 / vite-plugin-web-extension

Vite plugin for developing Chrome/Web Extensions
https://vite-plugin-web-extension.aklinker1.io/
MIT License
537 stars 46 forks source link

Static assets #167

Closed ferllings closed 6 months ago

ferllings commented 6 months ago

Hello, More a question than a bug.

I have some 3rd party libs, already minified, that I would like to include in my manifest:

          "js": [
              "external/lib.min.js"
          ],

How can include it, without processing/building it?

Thanks

aklinker1 commented 6 months ago

Put it in Vite's public directory.

ferllings commented 6 months ago

Yes, but I can not longer keep the record in the manifest: The file is in /public/lib/leader-line.min.js,

✓ 0 modules transformed.
Could not resolve entry module "src/lib/leader-line.min.js".
✓ 0 modules transformed.
[web-extension:manifest] Could not resolve entry module "src/lib/leader-line.min.js".
ferllings commented 6 months ago

Nevermind, I believe I found my mistake: It's working now

            "js": [
                "public/lib/leader-line.min.js"
            ],
ferllings commented 6 months ago

Looks like I spook too soon:

I put my lib into src/public/leader-line.min.js

Then in manifest

            "js": [
                "public/leader-line.min.js"
            ],

Vite put a unmodified copy on "dist/leader-line.min.js" and second but modified copy on "dist/public/leader-line.min.js"

If switch manifest.json, in order to use the "dist/leader-line.min.js" unmodified copy

            "js": [
                "leader-line.min.js"
            ],

It throws Could not resolve entry module "src/leader-line.min.js"

aklinker1 commented 6 months ago

@ferllings I've added a new feature to address this, could you try it out?

Install version 4.1.0-alpha1 (the @next tag on NPM), and add the "public:" prefix to your content script path.

"js": [
  "public:leader-line.min.js"
],

Make sure the file is in public/leader-line.min.js, and it should work for your.

ferllings commented 6 months ago

I'm afraid it still not working: Could not resolve entry module "public:leader-line.min.js"

I modified the manifest file:

Screenshot 2023-12-19 at 10 25 18

The installed node_module version is correct:

Screenshot 2023-12-19 at 10 21 52
aklinker1 commented 6 months ago

Interesting. Could you upload a zip of a minimal reproduction? The above was working for me in my test case.

ferllings commented 6 months ago

Here you go test-repo.zip

aklinker1 commented 6 months ago

Fix released in v4.1.0

ferllings commented 6 months ago

Thanks. I confirm it is working.