|
| 1 | +import { defineNuxtModule } from '@nuxt/kit'; |
| 2 | + |
1 | 3 | import type { Options } from './core/types';
|
2 | 4 |
|
3 | 5 | import { UnpluginInfo } from './core';
|
4 | 6 |
|
5 |
| -export default function (options: Options = {}, nuxt: any) { |
6 |
| - // install webpack plugin |
7 |
| - nuxt.hook('webpack:config', async (config: any) => { |
8 |
| - config.plugins = config.plugins || []; |
9 |
| - config.plugins.unshift(UnpluginInfo.webpack(options)); |
10 |
| - }); |
| 7 | +export default defineNuxtModule({ |
| 8 | + meta: { |
| 9 | + // Usually the npm package name of your module |
| 10 | + name: 'unplugin-info/nuxt', |
| 11 | + // The key in `nuxt.config` that holds your module options |
| 12 | + configKey: 'info', |
| 13 | + // Compatibility constraints |
| 14 | + compatibility: { |
| 15 | + // Semver version of supported nuxt versions |
| 16 | + nuxt: '^3.0.0' |
| 17 | + } |
| 18 | + }, |
| 19 | + // Default configuration options for your module, can also be a function returning those |
| 20 | + defaults: {}, |
| 21 | + // Shorthand sugar to register Nuxt hooks |
| 22 | + hooks: {}, |
| 23 | + setup(options: Options = {}, nuxt) { |
| 24 | + // install webpack plugin |
| 25 | + nuxt.hook('webpack:config', async (config: any) => { |
| 26 | + config.plugins = config.plugins || []; |
| 27 | + config.plugins.unshift(UnpluginInfo.webpack(options)); |
| 28 | + }); |
11 | 29 |
|
12 |
| - // install vite plugin |
13 |
| - nuxt.hook('vite:extendConfig', async (config: any) => { |
14 |
| - config.plugins = config.plugins || []; |
15 |
| - config.plugins.push(UnpluginInfo.vite(options)); |
16 |
| - }); |
17 |
| -} |
| 30 | + // install vite plugin |
| 31 | + nuxt.hook('vite:extendConfig', async (config: any) => { |
| 32 | + config.plugins = config.plugins || []; |
| 33 | + config.plugins.push(UnpluginInfo.vite(options)); |
| 34 | + }); |
| 35 | + } |
| 36 | +}); |
0 commit comments