crxjs / chrome-extension-tools

Bundling Chrome Extensions can be pretty complex. It doesn't have to be.
https://crxjs.dev/vite-plugin
2.9k stars 192 forks source link

Relative path with `"sideEffects": false` silently breaks pages #655

Closed filipw01 closed 1 year ago

filipw01 commented 1 year ago

Build tool

Vite

Where do you see the problem?

Describe the bug

There is a page declared in vite.config.js - page.html importing ./main.js

When there is "sideEffects": false declared in package.json vite bundles only modulepreload polyfill ignoring main.js

When there is no "sideEffects": false declared in package.json vite correctly bundles both modulepreload polyfill and main.js file into one file

When page.html imports /main.js instead (absolute path) it works as expected bundling both modulepreload polyfill and main.js file into one file

My fix is to use absolute paths, but I would expect either an error or relative paths working as expected

Reproduction

https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-ukxxhl?file=package.json

Logs

No response

System Info

You can see everything in reproduction too, but for me it's

System:
    OS: macOS 13.2.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 4.70 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.10.0 - ~/Library/Caches/fnm_multishells/2776_1676359517532/bin/node
    Yarn: 3.3.1 - /opt/homebrew/bin/yarn
    npm: 7.24.0 - ~/Library/Caches/fnm_multishells/2776_1676359517532/bin/npm
  Browsers:
    Chrome: 110.0.5481.100
    Firefox: 110.0
    Safari: 16.3

Severity

annoyance

filipw01 commented 1 year ago

Closing temporarily as I missed one thing in reproduction and after fixing it it seems to work. I need to provide a better one because I definitely see an issue locally

filipw01 commented 1 year ago

Found the actual issue, renamed issue and edited description

jacksteamdev commented 1 year ago

I was able to reproduce this with a vanilla Vite project, and it looks like Vite is tracking this bug in this issue.

Closing since it's a Vite issue.

jacksteamdev commented 1 year ago

@filipw01 This is a truly perfect minimal reproduction. Thank you! 🤗

We should add a link to a CRXJS project on StackBlitz, it makes everything so easy.

filipw01 commented 1 year ago

I didn't think it might be an issue with Vite itself. Thank you for the link. I might find a moment to add a link to StackBlitz somewhere

filipw01 commented 1 year ago

@jacksteamdev I created this vanilla js project which I think we could link in the issue template https://stackblitz.com/edit/stackblitz-webcontainer-api-starter-humgcr

Feel free to fork it with your account to be in full control of it