How to set an alias for a custom path in Vue

How to set an alias for a custom path in Vue

How to configure custom path aliases in Vue

In our daily development, we often import some modules or components. If we use relative paths:

import uEditor from "../../../../../components/tools";

It will appear bloated and redundant. If there is a slight mistake in the reference, a -404 error will appear, which is not elegant. 404 errors will often occur. If the file changes, you need to find the change path one by one and modify it again, which is very troublesome. Versions above vue cli3 provide a file alias function in node_modules. However, it is still recommended to modify the node_modules code as little as possible unless there is a special requirement.

Create vue.config.js and write the configuration code

module.exports = {
    configureWebpack: {
        resolve: {
            alias: { //Configure alias, you need to recompile after modification to take effect 'assets': '@/assets',
                'common': '@/common',
                'components': '@/components',
                'network': '@/network',
                'views': '@/views',
            }
        }
    }
}

As shown below:

Note: If you use an alias in an HTML path, you need to prefix the reference with "~".

Other references in the document:

The above is the method that I introduced to you in Vue to set aliases for custom paths. I hope it will be helpful to you. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Implementation of Vue alias path prompt in vscode
  • How to configure Vue's path alias in vue.config.js
  • Detailed explanation of Vue CL3 configuration path alias
  • Use alias path to reference static image address in webpack+vue
  • How to implement aliasing paths in Vue

<<:  Use pure CSS to disable the a tag in HTML without JavaScript

>>:  Teach you the detailed process of using Docker to build the Chinese version of gitlab community

Recommend

Docker uses the nsenter tool to enter the container

When using Docker containers, it is more convenie...

Some experience sharing on enabling HTTPS

As the domestic network environment continues to ...

CentOS 8 installation diagram (super detailed tutorial)

CentOS 8 is officially released! CentOS fully com...

32 Typical Column/Grid-Based Websites

If you’re looking for inspiration for columnar web...

How to configure Linux firewall and open ports 80 and 3306

Port 80 is also configured. First enter the firew...

CSS draw a lollipop example code

Background: Make a little progress every day, acc...

Mysql sets boolean type operations

Mysql sets boolean type 1. Tinyint type We create...

Examples of using the Li tag in HTML

I hope to align the title on the left and the dat...

Several scenarios for using the Nginx Rewrite module

Application scenario 1: Domain name-based redirec...

Execution context and execution stack example explanation in JavaScript

JavaScript - Principles Series In daily developme...

Vue+spring boot realizes the verification code function

This article example shares the specific code of ...

Using group by in MySQL always results in error 1055 (recommended)

Because using group by in MySQL always results in...