nuxt-community/nuxt-generate-cluster

Name: nuxt-generate-cluster

Owner: Nuxt Community

Description: Multi-threaded generator command for nuxt.js

Created: 2017-10-21 18:20:44.0

Updated: 2018-05-23 12:15:34.0

Pushed: 2018-02-18 15:43:41.0

Homepage:

Size: 223

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Multi-threaded generate command for Nuxt.js

Build Status Windows Build Status Coverage Status npm npm (scoped with tag)

Use multiple workers to generate the static files for your Nuxt.js project

Setup

Install the package with npm

 install --save nuxt-generate-cluster

or use yarn

 add nuxt-generate-cluster`

Optionally add a generate script to your package.json

cripts": {
"generate": "nuxt-generate -w 4"

Nuxt config options

Configure the generate options in nuxt.config.js

nerate: {
workers: 4,
workerConcurrency: 500,
concurrency: 500,
routes (callback, params) {
  return axios.get('https://api.example.com/routes?since=' + params.lastFinished)
  .then((res) => {
    return res.data
  })
},
done ({ duration, errors, workerInfo }) {
  if (errors.length) {
    axios.post('https://api.example.com/routes', { generate_errors: errors })
  }
}

workers

The number of workers that should be started. It probably has no use to start more workers then number of processors in your system.

workerConcurrency

To even the load between workers they are sent batches of routes to generate, otherwise a worker with 'easy' routes might finish long before others. Workers will also still use the concurrency option from Nuxt.

routes

The default Nuxt.js routes method has been extended so you can pass additional parameters to it, see params parameter in example config under Setup. By default it will list 3 timestamps:

Timestamps are locally stored in ~/.data-store/nuxt-generate-cluster.json, see data-store

done

This method will be called when all workers are finished, it receives three arguments:

type: 'handled',
route: '/non-existing-link',
error: 
 { statusCode: 404,
   message: 'The message from your 404 page' } }

6707':                            // the process id of the worker
 start: [ 1929158, 859524606 ],   // process.hrtime the worker was started
 duration: 109567,                // how long the worker was active
 signal: 0,                       // the signal by which the worker was killed (if any)
 code: 0,                         // the exit status of the worker
 routes: 73,                      // the number of routes generated by this worker
 errors: [] },                    // the errors this worker encountered, errors of all workers
                                  // combined is the error argument above

Command-line options

Please note that you need to explicitly indicate with -b that you want to (re-)build your project

xt-generate --help
Description
  Generate a static web application (server-rendered)
Usage
  $ nuxt-generate <dir>
Options
  -b, --build           Whether to (re-)build the nuxt project
  -c, --config-file     Path to Nuxt.js config file (default: nuxt.config.js)
  -h, --help            Displays this message
  -p, --params          Extra parameters which should be passed to routes method
                          (should be a JSON string or queryString)
  -w, --workers [NUM]   How many workers should be started
                          (default: # cpus)
  -wc [NUM],            How many routes should be sent to 
  --worker-concurrency [NUM]    a worker per iteration

  --spa               Launch in SPA mode
  --universal         Launch in Universal mode (default)

If you need to have more control which routes should be generated, use the -p option to pass additional parameters to your routes method.

xt.config.js
rate: {
utes (callback, params) {
console.log(params)



xt-generate -w 2 -p id=1&id=2
ill print =>
: [ '1', '2' ],
stStarted: 1508609323,
stBuilt: 0,
stFinished: 0 }

If you are using a npm script under bash use -- to pass the parameters to nuxt-generate instead of npm:

m run generate -- -p '{ "id": [1,2,3] }'
ill print =>
: [ 1, 2, 3 ],
stStarted: 1508786574,
stBuilt: 0,
stFinished: 0 }

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.