Reputation: 53
I have worked to a VueJs project locally. Now I have to upload it on a VM of my university and it will become public. I think I should not upload the entire directory but only the 'dist' directory that I created with the command:
npm run build
First question: Is it correct?
Second question: How do I run the server now? For local's test I used to run it with the command:
npm run serve
but I think now I should use some other commands.
Thank you for help.
Upvotes: 2
Views: 9149
Reputation: 11
The command npm run build
is correct for preparing the project for deployment.
You don't need to run the command npm run serve
like you do on local.
What you will need for deployment after running the command npm run build
are:
dist folder and index.html file.
You could deploy your project to any hosting provider you choose.
I will use aws s3 as example for a static application (The process is almost the same in other platforms).
Login to aws
Select s3
Create a new bucket (Give it a preferred name and select region)
Enable the option for Static Website Hosting on the bucket you just created. The fileds for Index Document and Error Document should be set to index.html
Set Bucket Permission (Add Bucket Policy)
Paste this into the bucket policy editor and save. Change your-bucketName to the created bucket name
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::your-bucketName/*"
]
}
]
}
Upload the files (build.js in the dist folder and index.js)
Create a folder with name as dist inside your bucket and move the build.js inside.
Click on All Buckets to go back. Select Properties of your deployed bucket at the top-right menu and click on Endpoint to lunch your hosted site.
Upvotes: 0
Reputation: 2823
just simply
npm run build
Copy index.html and /dist/ folder into your website root directory. Done.
Upvotes: 0
Reputation: 3270
Answer for questions:
Yes. It is correct.
Usually, you will need to serve the dist folder in a web server. Like nginx or apache.
It will work serving your index.html
, inside /dist
folder generated in the build step of your vuejs application.
Obs.: you should not serve your application in production with npm run serve
as it is a development server monothreaded.
Upvotes: 4