Skip to content

Commit

Permalink
feat: support customer module path & rename excludeConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangmo8 committed Apr 3, 2024
1 parent 56c379b commit 2c03c31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
14 changes: 8 additions & 6 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,12 +23,14 @@ function matchComponentName(componentStr: string): string {
return componentName.trim()
}

const transformPathPlugin = createUnplugin(() => {
const transformPathPlugin = createUnplugin<ModuleOptions>((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)
Expand Down Expand Up @@ -83,7 +85,7 @@ export default defineNuxtModule<ModuleOptions>({
nuxt.options.build.transpile.push(moduleName)

addComponentsDir({
path: `${relativePath}/es`,
path: `${_options?.modulePath || relativePath}/es`,
prefix: nameSpace,
pathPrefix: true,
extensions: ['js', 'vue', 'ts', 'mjs'],
Expand All @@ -103,12 +105,12 @@ export default defineNuxtModule<ModuleOptions>({

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))
})
})
},
Expand Down
6 changes: 2 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export interface ModuleOptions {
autoImport: boolean
lazyLoad?: boolean
include?: RegExp[]
exclude?: RegExp[]
modulePath?: string
exclude?: string[]
}

declare module '@nuxt/schema' {
Expand Down

0 comments on commit 2c03c31

Please sign in to comment.