Skip to content

feat: call resolveId hooks in urlToBuiltUrl#1647

Closed
aleclarson wants to merge 3 commits into
vitejs:mainfrom
aleclarson:feat/force-url
Closed

feat: call resolveId hooks in urlToBuiltUrl#1647
aleclarson wants to merge 3 commits into
vitejs:mainfrom
aleclarson:feat/force-url

Conversation

@aleclarson
Copy link
Copy Markdown
Contributor

This is useful for rewriting asset urls in index.html and .css files.

Also in this PR: When a resolveId hook's importer ends with .css or .html, the hook can prepend its return value with ! to signify a built url, which skips the fileToBuiltUrl call in urlToBuiltUrl. For example, if the resolving plugin called emitFile from its resolveId hook, it can return !__VITE_ASSET__xxx to be replaced by Vite later on.

I use these features in both vite-plugin-public and vite-plugin-rehost.

This is useful for rewriting asset urls in index.html and .css files
In some cases, rewritten asset urls do not point to actual files. For example, if the resolving plugin called `emitFile` from its `resolveId` hook, it can return "!__VITE_ASSET__xxx" to be replaced by Vite later on.
aleclarson added a commit to aleclarson/vite that referenced this pull request Jan 22, 2021
...and any local non-module `<script>` tags.

This is especially useful in combination with vitejs#1647.
..after `resolveId` hook calls.
@aleclarson
Copy link
Copy Markdown
Contributor Author

aleclarson commented Jan 23, 2021

Hmm, perhaps introducing a resolveAsset hook is a better approach than trying to use resolveId beyond its intended purpose, since testing the importer's extension is unintuitive and unreliable.

edit: I see that Rollup has resolveFileUrl hook, but it doesn't quite fit my needs. Rollup once had a resolveAssetUrl hook too, so maybe resolveBuiltUrl would be less confusing than resolveAsset.

@aleclarson
Copy link
Copy Markdown
Contributor Author

Closed in favor of #1675

@aleclarson aleclarson closed this Jan 23, 2021
@aleclarson aleclarson deleted the feat/force-url branch June 24, 2021 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant