question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow disabling of copying certain assets

See original GitHub issue

Description

During my transition from Rollup to Vite, I spent a lot of time trying to determine how to disable certain assets from getting copied into the bundle. In the SCSS of one of my components, I reference an image within my static/ folder using url() within the CSS. This causes the static asset handling to copy this image to my target output, which is static/bundle/. However, because my entire static/ folder is accessible, it is redundant to copy a file from a sibling folder, static/images/, and ends up doubling assets.

As a workaround, by setting outDir: "", assetsDir: "static/bundle/" (instead of outDir: "static", assetsDir: "bundle") I’m able to at least fix references so that the site will load normally (since /static/bundle is a valid URL but /bundle is not).

Suggested solution

I propose the addition of an assetsExclude option, which would essentially be the opposite of https://vitejs.dev/config/shared-options.html#assetsinclude. This would allow the user to add certain globs that should be left untouched. This option is highly useful for my use case, as I can confidently say that every file within static/ should not be bundled or transformed.

Alternative

An alternative solution could be to add a ?notransform suffix to URLs, which would allow explicitly setting a specific asset URL to not be transformed. This may be a useful option for filepaths that aren’t easy to glob for, or for one-offs.

Additional context

No response

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
queengooborgcommented, Sep 4, 2022

Alright then, I think I’m just going to stick with Rollup – even though the Vue Rollup plugin was officially discontinued, I’ve already run into a number of frustrating cases like this with Vite that I don’t want to pursue migrating to it any longer. Thank you anyways. 👍

0reactions
bluwycommented, Sep 4, 2022

What if I’m not using publicDir and I just don’t want any assets in the /static/ folder to be copied to the build, period?

That’s already the case today as long as you don’t explicitly import it. In the example you gave, url("/static/images/drips_navbar.png"), Vite is able to resolve this path the the actual file, so it will bundle it. It works because path starting with / are relative to your Vite project root.

Instead, you can reference it as url("/images/drips_navbar.png") so Vite can’t resolve it. But you have to manually serve files under /static using a middleware like sirv, injected via a Vite plugin configureServer hook. So that it works when fetched by the browser in dev.

This response is not applicable to the intended use case, as it expects the developer to use the Vite dev server, and does not take the build command into account. Furthermore, I am using a Python-based backend to host my website. (And no, converting the backend to a JavaScript-based system is out of the question.)

Yes I’m suggesting for dev specifically since I have no idea how you are serving files under static if you don’t want Vite to handle that for you. In dev, maybe the Python backend is already serving /static, then you can skip my suggestion. But if not, my suggestion would make dev work. However what comes after build and how it’s getting served depends on your Python backend.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I enable and disable assets in Exodus?
Click on the a) Settings icon, then b) click the Assets tab. To view all assets supported on Desktop, click the a) All...
Read more >
Cities: Skylines General Discussions - Steam Community
There is a simple "Disable All" button in the asset section. Most people want them though. If yu don't want them, just unsubscribe...
Read more >
Disabling Duplicate Selected - Community @ ShotGrid
If a Role has permission to “Create” a given Entity, then the Duplicate Selected option is available in the right-click menu. Duplicate Selected...
Read more >
Allow or prevent custom script - SharePoint in Microsoft 365
On the Settings page in the SharePoint admin center, to accept the custom script settings as they appear, select OK, and enable cross-site...
Read more >
Why is the Copy Local property for my reference disabled?
2. Interesting side note, you need to have the properties box set to categorized and not alphabetical. For some reason by alphabet locks...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found