Vue3 TS Vite development skills: how to deploy and go online
1. Project setup
Before we start, we must first ensure that Node has been installed. js and Vue CLI, and then execute the following command to create a new Vue3 TS Vite project:
vue create project-name
Next, select "Manually select features", then check "TypeScript", and finally press Enter to install.
2. Development environment configuration
Modify the Vite configuration file
Find the vite.config.ts file in the project root directory and modify the following content:
import { defineConfig } from 'vite' export default defineConfig({ base: './', })
After setting like this, the project will be packaged using the current path as the base path.
Configure deployment directory
Open the src/env/production.ts
file and modify publicPath
to the one you want to deploy the project Directory, for example:
export default { publicPath: '/your-project-name/', }
After setting like this, the packaged files will be automatically placed in the /your-project-name/
directory.
3. Project construction and packaging
Build the project
Execute the following command to build the project into a deployable static file:
npm run build
After the construction is completed, a dist
folder will be generated in the project root directory, which stores the packaged static files.
Local testing
You can start a server locally to test the packaged project through the following command:
npm install -g http-server cd dist http-server
Then open http in the browser ://localhost:8080
to view the project effect.
4. Deploy to the server
dist
folder All files are uploaded to your server using FTP tools or other methods. Make sure the file is uploaded to the correct directory. Configuring the server
On your server, you need to configure a nginx
(or other similar server software) to handle requests for static files. Assuming you are using nginx
, you can add the following content in the configuration file:
server { listen 80; server_name your-domain.com; location / { root /path/to/your-project/; try_files $uri $uri/ =404; } }
Note that your-domain.com
is replaced with your domain name,# Replace ##/path/to/your-project/ with the directory where you uploaded the project.
server to make the configuration take effect.
Through the above steps, we can deploy and go online the project developed based on Vue3 TS Vite so that it can run on the server. I hope this article can be helpful to you, and I wish your project goes online smoothly!
The above is the detailed content of Vue3+TS+Vite development skills: how to deploy and go online the project. For more information, please follow other related articles on the PHP Chinese website!