Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue.js Build not working with npm run build

Tags:

vue.js

I am trying to get vue.js source code for production. I used this command npm run build. I got a dist folder with index.html and a folder named static with all css and js.

When I tried running the index.html in localhost, ie, xampp server I got a blank page .

Is it possible with vue.js to run in xampp.

like image 1000
Omsun Kumar Avatar asked Dec 30 '16 07:12

Omsun Kumar


People also ask

How do I run a Vue project using npm?

Deploying the Vue sample app Navigate to the root folder of the application in the command line. Type npm install --global surge to install Surge on your computer. Type npm run build to build the application and make it production-ready. Type cd dist to navigate to the build folder.

Does Vue require npm?

Prerequisites. Install Node. js on Windows: This includes a version manager, package manager, and Visual Studio Code. The Node Package Manager (npm) is used to install Vue.

How does Vue CLI service Build work?

vue-cli-service build produces a production-ready bundle in the dist/ directory, with minification for JS/CSS/HTML and auto vendor chunk splitting for better caching. The chunk manifest is inlined into the HTML.


3 Answers

I had the same issue, and I solved the problem by deleting the "/" from the dist/index.html file. I had something like this:

<script src=/js/app.632f4e30.js></script>

And I change it to:

<script src=js/app.632f4e30.js></script>
like image 69
Amine Sehaba Avatar answered Oct 24 '22 04:10

Amine Sehaba


First create vue.config.js file in project root directory and define base url in it using below code

module.exports = {
  baseUrl: process.env.NODE_ENV === 'production'
    ? '/production-sub-path/'
    : '/'
}

If you use Vue CLI 3.3 or higher, use

module.exports = {
    publicPath: process.env.NODE_ENV === 'production' ?
      '/production-sub-path/' :
      '/'
}

Replace production-sub-path with your folder name ... eg. http://www.example.com/production-sub-path/ ... and run below command to build the project

npm run build

After finishing the build ... Copy/Upload all files in dist folder to your /production-sub-path/ folder... That's it

For more info checkout the official documentation https://cli.vuejs.org/guide/deployment.html#general-guidelines

like image 23
Sabeer Avatar answered Oct 24 '22 04:10

Sabeer


I had this issue before as well. I solved it by making a change to the index.js file in the config folder. Under build, I changed:

assetsPublicPath: '/',

to

assetsPublicPath: '',

and tried npm run build again. I checked the dist file and opened the index.html and it worked, no blank page.

like image 4
mintedsky Avatar answered Oct 24 '22 02:10

mintedsky