fix: add deprecated warn for tapables + simple backward compatibility

This commit is contained in:
Pooya Parsa 2017-11-07 17:18:46 +03:30
parent e5017c5e2a
commit 711e6a916e

View File

@ -58,6 +58,26 @@ export default class Nuxt {
return this
}
plugin(name, fn) {
// eslint-disable-next-line no-console
console.error(`[warn] nuxt.plugin('${name}',..) is deprecated. Please use new hooks system.`)
// A tiny backward compatibility util
const hookMap = {
'ready': 'ready',
'close': 'close',
'listen': 'listen',
'built': 'build:done'
}
if (hookMap[name]) {
this.hook(hookMap[name], fn)
}
// Always return nuxt class which has plugin() for two level hooks
return this
}
hook(name, fn) {
if (!name || typeof fn !== 'function') {
return