Module - use this.nuxt.plugin give error (how use new hook system correct)
[issue link]I wan’t to use module for WP API request in whole app and to easily copy on other projects.
Right now I get:
(node:7476) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: this.nuxt.plugin is not a function
Content of module file:
const { resolve } = require('path');
const defaults = {};
module.exports = async function wp (moduleOptions) {
let options = Object.assign({}, defaults, this.options['wp'], moduleOptions);
// this.addPlugin({
// src: resolve(__dirname, './templates/wp.plugin.js'),
// fileName: 'wp.plugin.js',
// options
// });
this.nuxt.plugin('generate', async generator => {
console.log(generator);
// This will be called when a Nuxt generate starts
}).then(function () {
console.log("Promise Resolved");
}).catch(function () {
console.log("Promise Rejected");
});
};
module.exports.meta = require('../package.json');
Documentation: https://nuxtjs.org/guide/modules/#run-tasks-on-specific-hooks
Where is error? No good example for use this.next
Found:
We have a new internal hook system now, some modules can be broken with 1.0 if they were relying on this.nuxt.plugin(), instead, they will have to use this.hook(), see module hooks documentation.
This isn’t show on documentation. Can somebody link where hook is show and work correct in last release?