Steps to package and deploy the Vue project to the Apache server

Steps to package and deploy the Vue project to the Apache server

In the development environment, the vue project is run through the npm run dev command, which is based on building an express server locally.

But this is not the case on the server. The entire project must be packaged using the npm run build command. After packaging, a dist folder will be generated in the project directory with the following contents:

Then just drop these files into a folder on the server. My folder name is ibms

Problems encountered:

1. Go directly to http://www.xxx.com/ibms/, you will find that the webpage is a white screen with nothing on it. This is quite strange. In fact, it is because there is a problem with the resource loading path!

Solution:

Modify the webpack configuration in build in index.js in config:

assetsPublicPath: '/ibms/'

Add the following to the index.js configuration in the router:

export default new Router({
 mode: 'history',
 scrollBehavior: () => ({ y: 0 }),
 base: '/ibms/', // add this line routes: constantRouterMap
})

Next, re-package it with npm run build, and then drop it into the ibms folder on the server. Then the page can be accessed normally.

2. Refresh the current page or use the URL bar to access a sub-page, and you will find that the webpage is 404. This is because the mode of Vue routing is history mode.

Solution:

Just forward all requests to http://www.xxx.com/ibms/index.html

I am using Apache as the web server here. Create a new .htaccess file in the ibms directory (at the same level as index.html) and edit the code.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /ibms/
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /ibms/index.html [L]
</IfModule>

The purpose of this configuration is to forward all requests that do not exist on the server to index.html. (PS: Remember to restart the Apache server)

This is the end of this article about the steps to package and deploy the Vue project to the Apache server. For more relevant Vue project packaging and deployment to Apache, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to automatically deploy vue-cli3 project to the server after packaging
  • Solution to the problem that the backend interface cannot be requested after the Vue3 project is packaged and deployed to the server
  • Configuration method of packaging and deploying Vue project to IIS server
  • Example of how to package and deploy a Vue project to a server
  • How to deploy Vue packaged files to the express server
  • Detailed example of how to package and deploy the Vue project webpack to the server

<<:  mysql delete multi-table connection deletion function

>>:  View the port number occupied by the process in Linux

Recommend

How to implement h5 input box prompt + normal text box prompt

XML/HTML CodeCopy content to clipboard < input...

Detailed explanation of memory management of MySQL InnoDB storage engine

Table of contents Storage Engine Memory Managemen...

CSS border adds four corners implementation code

1.html <div class="loginbody"> &l...

MySQL not null constraint case explanation

Table of contents Set a not null constraint when ...

Detailed tutorial on installing harbor private warehouse using docker compose

Overview What is harbor? The English word means: ...

Detailed explanation of Vue options

Table of contents 1. What are options? 2. What at...

Basic learning and experience sharing of MySQL transactions

A transaction is a logical group of operations. E...

Detailed explanation of how to install PHP curl extension under Linux

This article describes how to install the PHP cur...

Vue3 AST parser-source code analysis

Table of contents 1. Generate AST abstract syntax...

Detailed explanation of Angular routing sub-routes

Table of contents 1. Sub-route syntax 2. Examples...

MySQL prepare principle detailed explanation

Benefits of Prepare The reason why Prepare SQL is...