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.
  • —unix-socket or -n: specify the path to a UNIX socket.

Hooks

HookObjective
cli:buildErrorCaptures build errors in dev mode and display them on loading screen

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 with the same set of options passed to https.createServer, 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 ).When using Unix sockets, 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. "build": "nuxt build",
  8. "start": "nuxt start"
  9. }
  10. }

Note: we recommend putting in .npmignore 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-error
  2. // OR
  3. yarn generate --fail-on-error

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

When generating your web application with nuxt generate, given to asyncData and 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.
  • Deploy the created folder to your static hosting like Surge, GitHub Pages or nginx.

Another possible deployment method is to use Nuxt as a middleware in frameworks while in spa mode. This helps reduce server load and uses Nuxt in projects where SSR is not possible.