Building and deploying the NuxtJS application

Posted by Lemeechi on 2019-09-18 05:54:34 in Discovery Vue Journal (1152 views)

1909172

The Nuxt JS Crash Course did not include final building or deploying the finished project, so at the end I later did some exploration at the nuxtjs.org website on doing this.

After development work, typing npm run build in the project directory creates the production version of the application. The command window messages may look something like this.Nuxt build

The built production files will be in the .nuxt subdirectory. To start a server running the built files, npm start is typed. When the server starts, it will show production instead of development.Nuxt production server

As before, browsing to http://localhost:3000 will display the production application. To deploy the application to another server, on the internet for example, npm run generate is typed to produce the necessary deployment files. (You should be online if the application referenced another website, otherwise getaddrinfo ENOTFOUND error messages will be generated.) The generated code files will be purely JavaScript and HTML so will not require NodeJS to work. The messages appearing on the command window during the files generation will look similar to the ones before, but will have a different ending, such as this.Nuxt generate

As before, each page in the application has a corresponding .js file created. But now, these deployment files will be placed in a dist subdirectory. We can then copy the contents of this to the server we want the application to be on.

When I started my Apache server and browsed to http://localhost/brad/dadjokes/dist/index.html the first time, the application started, but the links for the three command buttons didn’t work as expected. They were referencing directories in the root (such as http://localhost/jokes and http://localhost/about). This will not be an issue if our application is big enough to be on its own domain or subdomain. But now I had to find out how to deploy the files to a subdirectory on the server.

I did a web search on nuxt deploy subdirectory. From Stack Overflow the solution given was to supply the base property for the router element in nuxt.config.js. So I opened the file and included

  router: {base:'/brad/dadjokes/dist/'},

and after regenerating the files again, the application now worked perfectly. (Setting the base to empty string or './' didn’t work.) You can view the application on the web where I later deployed it here.

Summary

NuxtJS is a framework that speeds up Vue development. After working through the Traversy Nuxt JS Crash Course, I went on to explore building and deploying the production application.

If you like this post please register or log in to be able to subscribe and be notified of new posts by Lemeechi.

 

Tags

2019    dadjokes    Lemeechi    npm    nuxt    nuxt build    nuxt generate    NuxtJS    nuxtjs.org    September 2019    Traversy    Vue    VueJS   

Comments

No comments yet.

Add Comment

(All values are required.)

 (Will not be published.)

Similar Posts

A first introduction to NuxtJS  |   The Vue JS crash course by Traversy  |   Building the Todo course application  |   May 2019 In Brief  |   Enhancing the plain HTML Todo app  |   Deploying the Todo app to the web  |  

 Close
Tweet