Which command do I use to generate the build of a Vue app?

vue.jsVuejs2Vue Cli

vue.js Problem Overview


What should I do after developing a Vue app with vue-cli?

In Angular there was some command that bundle all the scripts into one single script.

Is there something the same in Vue?

vue.js Solutions


Solution 1 - vue.js

I think you've created your project like this:

vue init webpack myproject

Well, now you can run

npm run build

Copy index.html and /dist/ folder into your website root directory. Done.

Solution 2 - vue.js

If you've created your project using:

vue init webpack myproject

You'd need to set your NODE_ENV to production and run, because the project has web pack configured for both development and production:

NODE_ENV=production npm run build

Copy dist/ directory into your website root directory.

If you're deploying with Docker, you'd need an express server, serving the dist/ directory.

Dockerfile

FROM node:carbon

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app
ADD . /usr/src/app
RUN npm install

ENV NODE_ENV=production

RUN npm run build

# Remove unused directories
RUN rm -rf ./src
RUN rm -rf ./build

# Port to expose
EXPOSE 8080
CMD [ "npm", "start" ]

Solution 3 - vue.js

in your terminal

npm run build

and you host the dist folder. for more see this video

Solution 4 - vue.js

If you run into problems with your path, maybe you need to change the assetPublicPath in your config/index.js file to your sub-directory:

http://vuejs-templates.github.io/webpack/backend.html

Solution 5 - vue.js

To deploy your application to prod environment add

"build": "vue-cli-service build --mode prod"

in your scripts in package.json file.

Open your main.js and add

Vue.config.productionTip = false;

right after your imports. Then open your cli in the project folder and run this command

npm run build

This will make a dist folder in your project directory you may upload that dist folder in your host and your website will be live

Solution 6 - vue.js

The vue documentation provides a lot of information on this on how you can deploy to different host providers.

npm run build

You can find this from the package json file. scripts section. It provides scripts for testing and development and building for production.

You can use services such as netlify which will bundle your project by linking up your github repo of the project from their site. It also provides information on how to deploy on other sites such as heroku.

You can find more details on this here

Solution 7 - vue.js

The commands for what specific codes to run are listed inside your package.json file under scripts. Here is an example of mine:

"scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },

If you are looking to run your site locally, you can test it with

npm serve

If you are looking to prep your site for production, you would use

npm build

This command will generate a dist folder that has a compressed version of your site.

Solution 8 - vue.js

THIS IS FOR DEPLOYING TO A CUSTOM FOLDER (if you wanted your app not in root, e.g. URL/myApp/) - I looked for a longtime to find this answer...hope it helps someone.

Get the VUE CLI at https://cli.vuejs.org/guide/ and use the UI build to make it easy. Then in configuration you can change the public path to /whatever/ and link to it URL/whatever.

Check out this video which explains how to create a vue app using CLI if u need more help: https://www.youtube.com/watch?v=Wy9q22isx3U

Solution 9 - vue.js

For NPM => npm run Build For Yarn => yarn run build

You also can check scripts in package.json file

Solution 10 - vue.js

You write down the below command being at the project root.

npm run build

Solution 11 - vue.js

First Install Vue Cli Globally

npm install -g @vue/cli

To create a new project, run:

vue create project-name

run vue

npm run serve 

Vue CLI >= 3 uses the same vue binary, so it overwrites Vue CLI 2 (vue-cli). If you still need the legacy vue init functionality, you can install a global bridge:

Vue Init Globally

npm install -g @vue/cli-init

vue init now works exactly the same as [email protected]

Vue Create App

vue init webpack my-project

Run developer server

npm run dev

Solution 12 - vue.js

This command is for start the development server :

npm run dev

Where this command is for the production build :

npm run build

Make sure to look and go inside the generated folder called 'dist'.
Then start push all those files to your server.

Solution 13 - vue.js

One way to do this without using VUE-CLI is to bundle the all script files into one fat js file and then reference that big fat javascript file into main template file.

I prefer to use webpack as a bundler and create a webpack.conig.js in the root directory of project. All the configs such as entry point, output file, loaders, etc.. are all stored in that config file. After that, I add a script in package.json file that uses webpack.config.js file for webpack configs and start watching files and create a Js bundled file into mentioned location in webpack.config.js file.

Solution 14 - vue.js

I think you can use vue-cli

If you are using Vue CLI along with a backend framework that handles static assets as part of its deployment, all you need to do is making sure Vue CLI generates the built files in the correct location, and then follow the deployment instruction of your backend framework.

If you are developing your frontend app separately from your backend - i.e. your backend exposes an API for your frontend to talk to, then your frontend is essentially a purely static app. You can deploy the built content in the dist directory to any static file server, but make sure to set the correct baseUrl

Solution 15 - vue.js

  1. npm run build - this will uglify and minify the codes

  2. save index.html and dist folder in root directory of your website.

  3. free hosting service that you might be interested in -- Firebase hosting.

Solution 16 - vue.js

if you used vue-cli and webpack when you created your project.

you can use just

npm run build command in command line, and it will create dist folder in your project. Just upload content of this folder to your ftp and done.

Solution 17 - vue.js

If you are using npm u can use npm run build but if you are using yarn you can simply run yarn build

Solution 18 - vue.js

If you want to build and send to your remote server you can use cli-service (https://cli.vuejs.org/guide/cli-service.html) you can create tasks to serve, build and one to deploy with some specific plugins as vue-cli-plugin-s3-deploy

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionartem0071View Question on Stackoverflow
Solution 1 - vue.jsEgor StambakioView Answer on Stackoverflow
Solution 2 - vue.jsAkinjideView Answer on Stackoverflow
Solution 3 - vue.jsanasmorahhibView Answer on Stackoverflow
Solution 4 - vue.jsjntmeView Answer on Stackoverflow
Solution 5 - vue.jsMaBbKhawajaView Answer on Stackoverflow
Solution 6 - vue.jsBrianDevView Answer on Stackoverflow
Solution 7 - vue.jsGene YllanesView Answer on Stackoverflow
Solution 8 - vue.jsRick K.View Answer on Stackoverflow
Solution 9 - vue.jsZaheer AlviView Answer on Stackoverflow
Solution 10 - vue.jsSaurav guptaView Answer on Stackoverflow
Solution 11 - vue.jsJamil AhmedView Answer on Stackoverflow
Solution 12 - vue.jsFarcrew RzView Answer on Stackoverflow
Solution 13 - vue.jsYash_6795View Answer on Stackoverflow
Solution 14 - vue.jsLoveun CGView Answer on Stackoverflow
Solution 15 - vue.jsuser10543871View Answer on Stackoverflow
Solution 16 - vue.jsuser3348410View Answer on Stackoverflow
Solution 17 - vue.jsKaddu LivingstoneView Answer on Stackoverflow
Solution 18 - vue.jsdoijuniorView Answer on Stackoverflow