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

Vite doesn't transform new URL( "/src/assets/") in production build #4416

Closed
6 tasks done
Topograph opened this issue Jul 28, 2021 · 3 comments · Fixed by #4482
Closed
6 tasks done

Vite doesn't transform new URL( "/src/assets/") in production build #4416

Topograph opened this issue Jul 28, 2021 · 3 comments · Fixed by #4482

Comments

@Topograph
Copy link

Topograph commented Jul 28, 2021

Describe the bug

instead of this:

new URL("../../../../assets/images/books/book1/de/Cover_00.jpg", import.meta.url)

i would like to use this

new URL("/src/assets/images/books/book1/de/Cover_00.jpg", import.meta.url)

or even better use a @/ alias for the src directory.

in development mode both versions work while for production only the first variant will get transformed, while /src points to C:/src or whatever file system you`re in.

In the documentation it is stated that

During the production build, Vite will perform necessary transforms so that the URLs still point to the correct location even after bundling and asset hashing.

Is /src.. not considered a relative path, or is this a bug?

Edit 2021.08.02: I think i narrowed the problem down while trying to create a reproduction setup. Sorry for being too lazy to do this earlier.
I think the problem has to do using the imported URLs in a computed variable. (see HelloWorld.vue: 23) and has NOTHING to do with weather the URL starts with / or ./ or whatever.

Reproduction

Link to github repo: https://github.com/Topograph/vite-issue-4416-reproduction

Reproduce issue #4416 like this

  1. npm install

  2. npm run dev

  3. see http://localhost:3000/ and you should see 4 images. toggling the "greyscale" button changes the image sources

  4. npm run build or npm run serve to inspect production build

  5. open the production build in a browser. you should see, that

    a. Not all assets have been exported (assetsInlineLimit is set to 0, in order to avoid inlining images.)

    b. There is an error in the developer console. following it in the production js (dist/assets/index.*.js) you will see, that not all the new URL("") paths have been correctly transformed


### System Info

```shell
System:
    OS: Windows 10 10.0.19041
    CPU: (16) x64 AMD Ryzen 7 1700X Eight-Core Processor
    Memory: 1.99 GB / 7.95 GB
  Binaries:
    Node: 14.16.1 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.12 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 92.0.4515.107
    Edge: Spartan (44.19041.1023.0), Chromium (92.0.902.55)
    Internet Explorer: 11.0.19041.1
  npmPackages:
    @vitejs/plugin-vue: ^1.2.5 => 1.2.5
    vite: ^2.4.2 => 2.4.2

Used Package Manager

npm

Logs

No response

Validations

@dejour
Copy link
Contributor

dejour commented Aug 2, 2021

could you provide a reproduction repo.

@github-actions
Copy link

github-actions bot commented Aug 2, 2021

Hello @Topograph. Please provide a minimal reproduction using a GitHub repository or codesandbox. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@Topograph
Copy link
Author

Topograph commented Aug 2, 2021

hi! sorry for being lazy- it took some me some time to figure out, how i could reproduce my issue in a simple project. i created a project and linked the github repo. Following the steps in the README.md should make the error clear.

https://github.com/Topograph/vite-issue-4416-reproduction

@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants