A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://vue-loader.vuejs.org/guide/asset-url.html below:

Website Navigation


Asset URL Handling | Vue Loader

# Asset URL Handling

When Vue Loader compiles the <template> blocks in SFCs, it also converts any encountered asset URLs into webpack module requests.

For example, the following template snippet:

will be compiled into:

By default the following tag/attribute combinations are transformed, and can be configured using the transformAssetUrls option.

In addition, if you have configured to use css-loader for the <style> blocks, asset URLs in your CSS will also be processed in a similar fashion.

# Transform Rules

Asset URL transforms adhere to the following rules:

Because extensions like .png are not JavaScript modules, you will need to configure webpack to use file-loader or url-loader to properly handle them. Projects created with Vue CLI has this pre-configured.

# Why

The benefits of asset URL transforms are:

  1. file-loader allows you to designate where to copy and place the asset file, and how to name it using version hashes for better caching. Moreover, this also means you can just place images next to your *.vue files and use relative paths based on the folder structure instead of worrying about deployment URLs. With proper config, webpack will auto-rewrite the file paths into correct URLs in the bundled output.

  2. url-loader allows you to conditionally inline a file as base-64 data URL if they are smaller than a given threshold. This can reduce the amount of HTTP requests for trivial files. If the file is larger than the threshold, it automatically falls back to file-loader.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4