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

JS url imports are inlined in production #13095

Closed
7 tasks done
NickTomlin opened this issue May 4, 2023 · 2 comments
Closed
7 tasks done

JS url imports are inlined in production #13095

NickTomlin opened this issue May 4, 2023 · 2 comments

Comments

@NickTomlin
Copy link

NickTomlin commented May 4, 2023

Describe the bug

I'd like to use a reference to a JS file to be loaded on-demand. In development, I can use the import ("path?url") or new URL("path", import.meta.url).hrf approaches outlined in static assets to get the resolved url to the file.

In production, the file is inlined (data:application/javascript;base64,ZXhw) regardless of the method I use. I would expect this to resolve to something like assets/path-9d3f80c0.js.

I think the approaches outlined in #2173 might work, but it would be ideal if url was honored and not inlined.

Reproduction

https://stackblitz.com/edit/vitejs-vite-9w3pt3?file=main.js,.vscode%2Fsettings.json,package.json&terminal=prod

Steps to reproduce

Run npm run build && npm run preview

Run npm run dev (or see this example) to see the dev behavior.

System Info

npx envinfo --system --npmPackages '{vite,@vitejs/*}' --binaries --browsers


success Install finished in 1.097s


  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    vite: ^4.3.2 => 4.3.4

Used Package Manager

pnpm

Logs

No response

Validations

@stackblitz
Copy link

stackblitz bot commented May 4, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@NickTomlin NickTomlin changed the title JS is inlined in production JS url imports are inlined in production May 4, 2023
@fi3ework
Copy link
Member

fi3ework commented May 5, 2023

Duplicate of #2173, let's track the resolution which provided a fine-grained control in #8717.

@fi3ework fi3ework closed this as completed May 5, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants