Skip to content

Commit 9a7ab2a

Browse files
committed
feat: add more nuxt module support
1 parent 8f4ea6e commit 9a7ab2a

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

src/nuxt.ts

+31-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
1+
import { defineNuxtModule } from '@nuxt/kit';
2+
13
import type { Options } from './core/types';
24

35
import { UnpluginInfo } from './core';
46

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+
});
1129

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

Comments
 (0)