diff --git a/src/config.ts b/src/config.ts index 5a59269..452a88b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -15,4 +15,4 @@ export const functional: string[] = [ export const directives = ['ripple', 'lazy', 'hover'] -export const excludeDiretries = ['.nuxt', 'node_modules'] +export const excludeFolders = ['.nuxt', 'node_modules'] diff --git a/src/module.ts b/src/module.ts index d298926..838df37 100644 --- a/src/module.ts +++ b/src/module.ts @@ -6,7 +6,7 @@ import MagicString from 'magic-string' import { genImport } from 'knitwork' import type { ModuleOptions } from './types' -import { directives, excludeDiretries, functional, moduleName, nameSpace } from './config' +import { directives, excludeFolders, functional, moduleName, nameSpace } from './config' import { genStylePath, pascalCase } from './utils' const componentReg = /_component_(v|V)ar([A-z]|_)+ /g @@ -23,12 +23,14 @@ function matchComponentName(componentStr: string): string { return componentName.trim() } -const transformPathPlugin = createUnplugin(() => { +const transformPathPlugin = createUnplugin((pluginOptions) => { + const { exclude = [] } = pluginOptions + return { name: `${moduleName}:transform`, enforce: 'post', transformInclude(id) { - return !excludeDiretries.some(entry => id.includes(entry)) + return ![...excludeFolders, ...exclude].some(entry => id.includes(entry)) }, transform(_code) { const code: MagicString = new MagicString(_code) @@ -83,7 +85,7 @@ export default defineNuxtModule({ nuxt.options.build.transpile.push(moduleName) addComponentsDir({ - path: `${relativePath}/es`, + path: `${_options?.modulePath || relativePath}/es`, prefix: nameSpace, pathPrefix: true, extensions: ['js', 'vue', 'ts', 'mjs'], @@ -103,12 +105,12 @@ export default defineNuxtModule({ nuxt.hook('vite:extendConfig', (config) => { config.plugins = config.plugins || [] - config.plugins.push(transformPathPlugin.vite()) + config.plugins.push(transformPathPlugin.vite(_options)) }) nuxt.hook('webpack:config', (configs) => { configs.forEach((config) => { - config.plugins.push(transformPathPlugin.webpack()) + config.plugins.push(transformPathPlugin.webpack(_options)) }) }) }, diff --git a/src/types.ts b/src/types.ts index c0856e4..201c2b6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,8 +1,6 @@ export interface ModuleOptions { - autoImport: boolean - lazyLoad?: boolean - include?: RegExp[] - exclude?: RegExp[] + modulePath?: string + exclude?: string[] } declare module '@nuxt/schema' {