Commands and Deployment

Arguments

You can use —help with any command to get detailed usage. Common arguments are:

  • —config-file or -c: specify the path to nuxt.config.js file.
  • —spa or -s: Runs command in SPA mode and disables server side rendering.

Using in package.json

You should put these commands in the package.json:

Then, you can launch your commands via npm run <command> (example: npm run dev).

Pro tip: to pass arguments to npm commands, you need an extra script name (example: npm run dev — —spa).

To launch Nuxt in development mode with hot reloading:

  1. nuxt
  2. // OR
  3. npm run dev

Nuxt.js lets you choose between three modes to deploy your application: SSR, Static Generated, or SPA.

You can also set server.https in your nuxt.config.js with the same set of options passed to , should you choose to serve Nuxt.js in HTTPS mode.Unix sockets are also available if you set the server.socket option in nuxt.config.js (or -n in the CLI).When using , make sure not to set the host and port parameters otherwise the socket parameter is ignored.

The package.json like follows is recommended:

  1. {
  2. "name": "my-app",
  3. "dependencies": {
  4. "nuxt": "latest"
  5. },
  6. "scripts": {
  7. "dev": "nuxt",
  8. "start": "nuxt start"
  9. }
  10. }

Note: we recommend putting .nuxt in or .gitignore.

Nuxt.js gives you the ability to host your web application on any static hosting.

To generate our web application into static files:

It will create a dist folder with everything inside ready to be deployed on a static hosting site.

  1. npm run generate --fail-on-page-error
  2. // OR
  3. yarn generate --fail-on-page-error

If you have a project with dynamic routes, take a look at the to tell Nuxt.js how to generate these dynamic routes.

When generating your web application with nuxt generate, the context given to and fetch will not have req and res.

nuxt generate still needs its SSR engine during build/generate time while having the advantage of having all our pages pre rendered, and have a high SEO and page load score. The content is generated at build time. For example, we can't use it for applications where content depends on user authentication or a real time API (at least for the first load).

The SPA idea is simple! When SPA mode is enabled using mode: 'spa' or —spa flag, and we run build, generation automatically starts after the build. This generation contains common meta and resource links, but not page content.

So, for an SPA deployment, you must do the following:

  • Change mode in nuxt.config.js to spa.
  • Run npm run build.

Read our and find nifty examples for deployments to popular hosts.