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 tonuxt.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:
nuxt
// OR
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:
{
"name": "my-app",
"dependencies": {
"nuxt": "latest"
},
"scripts": {
"dev": "nuxt",
"start": "nuxt start"
}
}
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.
npm run generate --fail-on-page-error
// OR
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
innuxt.config.js
tospa
. - Run
npm run build
.
Read our and find nifty examples for deployments to popular hosts.