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

Implementation code for partial refresh of HTML page

Event response refresh: refresh only when request...

Several methods to clear floating (recommended)

1. Add an empty element of the same type, and the...

JavaScript Closures Explained

Table of contents 1. What is a closure? 2. The ro...

How to install a virtual machine with Windows services on Mac

1. Download the virtual machine Official download...

Pure HTML and CSS to achieve JD carousel effect

The JD carousel was implemented using pure HTML a...

Use the more, less, and cat commands in Linux to view file contents

In Linux, the commands cat, more, and less can al...

Several ways to implement image adaptive container with CSS (summary)

There is often a scenario where the image needs t...

How to reference external CSS files and iconfont in WeChat applet wxss

cause The way to import external files into a min...

How to allow remote connection in MySql

How to allow remote connection in MySql To achiev...