Export `fileToUrl` function for plugins
See original GitHub issueClear and concise description of the problem
Vite’s some internal plugins uses the internal helper function fileToUrl
, which emits asset file to dev-server/bundle and return a URL for using in generated module code. It’s also very useful for external plugins to emit asset files.
Suggested solution
Export fileToUrl
function from Vite and document it in the docs.
Alternative
Plugin authors could copy the code from fileToUrl
from their plugins. This is very inelegant.
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:9 (8 by maintainers)
Top Results From Across the Web
How to correctly export and import functions for cypress plugin ...
In this video I see that there is a way to store functions in separate files and then export them using module.exports =...
Read more >File.js-1 Source Code | ExtReact - Sencha Documentation
url: function() {. //<debug>. Ext.log.warn('Exporter Plugin\'s file transformation server https://exporter.sencha.com ' +. 'will be deprecated (turned down) ...
Read more >File.toURL() returns wrong result for UNC pathname (win)
Bug - A problem which impairs or prevents the functions of the product. JDK-6585937 URL.getFile() returns different results for UNC pathnames.
Read more >Export url products - WordPress.org
By default, WooCommerce core export functionality does not include a URL ... Upon checking, it sounds like the WP All Import plugin will...
Read more >Writing Plugins - Intuit
import { Auto, IPlugin } from "auto"; export default class TestPlugin ... of the options passed to plugins, auto uses io-ts and exports...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m working on a plugin bringing WebAssembly ESM integration to Vite, which is equivalent to Webpack’s asyncWebAssembly.
I need to emit the WASM file just like the internal
wasm
plugin but I have no way to do it. My workaround is calling the original plugin’sload
function, which is inelegant and won’t work for other types of files (for those without a internal plugin in Vite that emits the file directly).https://github.com/Menci/vite-plugin-wasm/blob/e501eb234ad22d81d9bc94cb20086b759b4b07df/src/index.ts#L50-L52
If it’s in JS, I think
import url from './something.js?url'
could be used for now.@Menci For example for your plugin, I guess this part https://github.com/Menci/vite-plugin-wasm/blob/d98e0384950b6aea3156031a17ae65d28bbc7abd/src/index.ts#L37-L57 could be like
or