15

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.

2
  • the blank page could mean that there is some js error, could you open browser dev tools js console and see what is there? Commented Jan 26, 2017 at 8:44
  • Did you use vue-cli? Commented Nov 25, 2017 at 9:04

10 Answers 10

11

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

Sign up to request clarification or add additional context in comments.

2 Comments

for those getting the following error: Invalid options in vue.config.js: "baseUrl" is not allowed I was able to fix it by changing baseUrl to publicPath instead
If using Vue CLI > 3.3 know that baseUrl is deprecated and publicPath should be used
4

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.

Comments

3

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>

Comments

3

I created vue.config.js next to the file package.json

With the following content:

module.exports = {
    publicPath: ''
}

And run npm run build

It solved my problem

The following links helped me

https://github.com/vuejs-templates/webpack/issues/310

https://cli.vuejs.org/config/#vue-config-js

1 Comment

Take into account this is correct for Vue CLI > 3.3, if not you should use baseUrl instead
2

Usually when you do a production build the paths that get set in the index.html file prepend a slash in front of it meaning that it will look for the file in the base domain. So im guessing your just trying to open the file in the browser by double clicking the index.html file and having it open in the browser.

Something like file:///Users/brianvoelker/Desktop/websites/vue-build/docs/index.html So in that example it is trying to look for files in file:/// and of course the dont exist.

So you can do either two things open the index.html file and remove the slash at the beginning or just know when you deploy that it will work because the files lookup are relative to the base domain.

P.S. If your looking for a cli build tool check out Vue-build.com

1 Comment

actually, double-clicking the file opens the file correctly, problem is the build was not successful and the index is blank
1

Open vue.config.js you see the following code.

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true
})

update code to this

 const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  publicPath:''
})

Comments

0

Vue.js is a browser side app framework. The server side technology does not matter, unless you are attempting to do server side rendering.

npm run build works perfectly alright, and it creates a minified set of files for manifest.#.js, vendor.#.js and app.#.js

Open the network tab in developer tools of Google Chrome to see what files are getting loaded. If any of the js files are not getting loaded, it is a path configuration that you need to do, so that your server serves the right files.

You may have to tweak the index.html file a bit so that it fully meets your requirements, and move the js files from dist/static folder to your preferred location. The url path does not matter, as long as the app files are served in the right order.

Comments

0

I encountered a similar issue and the above info helped me. However, I found that if you edit the index.js file in the config folder for the VueJS CLI webpack tooling and edit the 'assetsPublicPath:' variable to './' from the default '/' then future builds will find the correct references to the css and js files in the static folder.

Comments

0

I have solved this by adding this code under root directory,

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

or you can remove first '/' from index.html file that has been created under dist. example href=/js/chunk-vendors.7a32d01e.js to href=js/chunk-vendors.7a32d01e.js

Comments

0

I had the same situation with a different issue, I used the vuejs-webpack-project project and tried running the output files under an IIS server.

This code in index.html didn't work:

<!DOCTYPE html>
<html>
<head>
  <meta charset=utf-8>
  <meta name=viewport content="width=device-width,initial-scale=1">
  <title>vuejs-webpack-project</title>
  <link href=/static/css/app.30790115300ab27614ce176899523b62.css rel=stylesheet>
</head>
<body>
  <div id=app />
  <script type=text/javascript src=/static/js/manifest.2ae2e69a05c33dfc65f8.js />
  <script type=text/javascript src=/static/js/vendor.4ad267b4786a3ebd3327.js />
  <script type=text/javascript src=/static/js/app.b22ce679862c47a75225.js />
</body>
</html>

This code worked(needed to change the closing tags of the script elemet):

<body>
    <div id=app />
    <script type=text/javascript src=/static/js/manifest.2ae2e69a05c33dfc65f8.js></script>
    <script type=text/javascript src=/static/js/vendor.4ad267b4786a3ebd3327.js></script>
    <script type=text/javascript src=/static/js/app.b22ce679862c47a75225.js ></script>
</body>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.