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

Typescript+react to achieve simple drag and drop effects on mobile and PC

This article shares the specific code of typescri...

How to reset the root password in Linux mysql-5.6

1. Check whether the MySQL service is started. If...

Install mysql offline using rpm under centos 6.4

Use the rpm installation package to install mysql...

Vue implements a simple calculator

This article example shares the specific code of ...

Example analysis of the principle and solution of MySQL sliding order problem

This article uses examples to explain the princip...

Linux Operation and Maintenance Basic System Disk Management Tutorial

1. Disk partition: 2. fdisk partition If the disk...

JS+Canvas realizes dynamic clock effect

A dynamic clock demo based on Canvas is provided ...

Mybatis implements SQL query interception and modification details

Preface One of the functions of an interceptor is...

MySQL GROUP_CONCAT limitation solution

effect: The GROUP_CONCAT function can concatenate...

Example of how to adapt the Vue project to the large screen

A brief analysis of rem First of all, rem is a CS...

Detailed explanation of jquery tag selector application example

This article example shares the specific code of ...

Example of how nginx implements dynamic and static separation

Table of contents Deploy nginx on server1 Deploy ...

The difference between name and value in input tag

type is the control used for input and output in t...