From d0064c84a570e3133302803e015ae2552ca2a82a Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sat, 31 Aug 2024 02:16:15 +0900 Subject: [PATCH] fix(unplugin-vue-i18n): plugin option made be optional (#390) --- packages/unplugin-vue-i18n/src/index.ts | 15 +++++++++++---- packages/unplugin-vue-i18n/src/vite.ts | 11 +++++++++-- packages/unplugin-vue-i18n/src/webpack.ts | 10 ++++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/unplugin-vue-i18n/src/index.ts b/packages/unplugin-vue-i18n/src/index.ts index 4861208..31e3033 100644 --- a/packages/unplugin-vue-i18n/src/index.ts +++ b/packages/unplugin-vue-i18n/src/index.ts @@ -3,12 +3,18 @@ import createDebug from 'debug' import { raiseError, checkInstallPackage, resolveNamespace } from './utils' import { resolveOptions, resourcePlugin, directivePlugin } from './core' +import type { UnpluginFactory, UnpluginInstance } from 'unplugin' import type { PluginOptions } from './types' const debug = createDebug(resolveNamespace('root')) const installedPkgInfo = checkInstallPackage(debug) -export const unplugin = createUnplugin((options = {}, meta) => { +export * from './types' + +export const unpluginFactory: UnpluginFactory = ( + options = {}, + meta +) => { debug('meta framework', meta.framework) // check bundler type if (!['vite', 'webpack'].includes(meta.framework)) { @@ -31,8 +37,9 @@ export const unplugin = createUnplugin((options = {}, meta) => { } return plugins -}) +} -export default unplugin +export const unplugin: UnpluginInstance = + /* #__PURE__ */ createUnplugin(unpluginFactory) -export * from './types' +export default unplugin diff --git a/packages/unplugin-vue-i18n/src/vite.ts b/packages/unplugin-vue-i18n/src/vite.ts index 589f4b9..705ca5b 100644 --- a/packages/unplugin-vue-i18n/src/vite.ts +++ b/packages/unplugin-vue-i18n/src/vite.ts @@ -1,3 +1,10 @@ -import unplugin from '.' +import { createVitePlugin } from 'unplugin' +import { unpluginFactory } from '.' -export default unplugin.vite +import type { UnpluginInstance } from 'unplugin' +import type { PluginOptions } from './types' + +const vite: UnpluginInstance['vite'] = + createVitePlugin(unpluginFactory) + +export default vite diff --git a/packages/unplugin-vue-i18n/src/webpack.ts b/packages/unplugin-vue-i18n/src/webpack.ts index 83091ee..d0b9dda 100644 --- a/packages/unplugin-vue-i18n/src/webpack.ts +++ b/packages/unplugin-vue-i18n/src/webpack.ts @@ -1,3 +1,9 @@ -import unplugin from '.' +import { createWebpackPlugin } from 'unplugin' +import { unpluginFactory } from '.' -export default unplugin.webpack +import type { UnpluginInstance } from 'unplugin' +import type { PluginOptions } from './types' + +const webpack: UnpluginInstance['webpack'] = + createWebpackPlugin(unpluginFactory) +export default webpack