fix(nuxt): autoImport judgement
parent
fbc12930b1
commit
7cf7fa6c1c
|
@ -1,9 +1,6 @@
|
||||||
import { addPlugin, addPluginTemplate, addTemplate, createResolver, defineNuxtModule } from '@nuxt/kit';
|
import { addPlugin, addPluginTemplate, addTemplate, createResolver, defineNuxtModule } from '@nuxt/kit';
|
||||||
import { isNotEmpty } from '@primeuix/utils';
|
|
||||||
import { PrimeVueResolver } from '@primevue/auto-import-resolver';
|
|
||||||
import type { MetaType } from '@primevue/metadata';
|
import type { MetaType } from '@primevue/metadata';
|
||||||
import { normalize } from 'pathe';
|
import { normalize } from 'pathe';
|
||||||
import Components from 'unplugin-vue-components/nuxt';
|
|
||||||
import { register } from './register';
|
import { register } from './register';
|
||||||
import type { ModuleOptions } from './types';
|
import type { ModuleOptions } from './types';
|
||||||
|
|
||||||
|
@ -62,31 +59,6 @@ export default defineNuxtModule<ModuleOptions>({
|
||||||
|
|
||||||
let registeredStyles: MetaType[] = registered.styles;
|
let registeredStyles: MetaType[] = registered.styles;
|
||||||
|
|
||||||
if (autoImport) {
|
|
||||||
const dts = isNotEmpty(moduleOptions.components?.prefix) || isNotEmpty(moduleOptions.directives?.prefix);
|
|
||||||
|
|
||||||
Components(
|
|
||||||
{
|
|
||||||
dts,
|
|
||||||
resolvers: [
|
|
||||||
PrimeVueResolver({
|
|
||||||
components: moduleOptions.components,
|
|
||||||
directives: moduleOptions.directives,
|
|
||||||
resolve: (meta: MetaType) => {
|
|
||||||
registeredStyles.push({
|
|
||||||
...meta,
|
|
||||||
name: `${meta.name}Style`,
|
|
||||||
as: `${meta.as}Style`,
|
|
||||||
from: `${meta.from}/style`
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
]
|
|
||||||
},
|
|
||||||
nuxt
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const styleContent = () => {
|
const styleContent = () => {
|
||||||
if (!loadStyles) return `export const styles = [], stylesToTop = [], themes = [];`;
|
if (!loadStyles) return `export const styles = [], stylesToTop = [], themes = [];`;
|
||||||
|
|
||||||
|
@ -145,7 +117,7 @@ export { styles, stylesToTop, themes };
|
||||||
import { defineNuxtPlugin, useRuntimeConfig } from '#imports';
|
import { defineNuxtPlugin, useRuntimeConfig } from '#imports';
|
||||||
${registered.config.map((config: MetaType) => `import ${config.as} from '${config.from}';`).join('\n')}
|
${registered.config.map((config: MetaType) => `import ${config.as} from '${config.from}';`).join('\n')}
|
||||||
${registered.services.map((service: MetaType) => `import ${service.as} from '${service.from}';`).join('\n')}
|
${registered.services.map((service: MetaType) => `import ${service.as} from '${service.from}';`).join('\n')}
|
||||||
${!autoImport && registered.directives.map((directive: MetaType) => `import ${directive.as} from '${directive.from}';`).join('\n')}
|
${autoImport && registered.directives.map((directive: MetaType) => `import ${directive.as} from '${directive.from}';`).join('\n')}
|
||||||
${importPT ? `import ${importPT.as} from '${normalize(importPT.from)}';\n` : ''}
|
${importPT ? `import ${importPT.as} from '${normalize(importPT.from)}';\n` : ''}
|
||||||
${hasTheme && importTheme ? `import ${importTheme.as} from '${normalize(importTheme.from)}';\n` : ''}
|
${hasTheme && importTheme ? `import ${importTheme.as} from '${normalize(importTheme.from)}';\n` : ''}
|
||||||
|
|
||||||
|
@ -158,7 +130,7 @@ export default defineNuxtPlugin(({ vueApp }) => {
|
||||||
|
|
||||||
usePrimeVue && vueApp.use(PrimeVue, { ...options, ...pt, ...theme });
|
usePrimeVue && vueApp.use(PrimeVue, { ...options, ...pt, ...theme });
|
||||||
${registered.services.map((service: MetaType) => `vueApp.use(${service.as});`).join('\n')}
|
${registered.services.map((service: MetaType) => `vueApp.use(${service.as});`).join('\n')}
|
||||||
${!autoImport && registered.directives.map((directive: MetaType) => `vueApp.directive('${directive.name}', ${directive.as});`).join('\n')}
|
${autoImport && registered.directives.map((directive: MetaType) => `vueApp.directive('${directive.name}', ${directive.as});`).join('\n')}
|
||||||
});
|
});
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ function registerComponents(resolvePath: any, moduleOptions: ModuleOptions) {
|
||||||
global: true
|
global: true
|
||||||
};
|
};
|
||||||
|
|
||||||
!moduleOptions.autoImport && addComponent(opt);
|
moduleOptions.autoImport && addComponent(opt);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
..._item,
|
..._item,
|
||||||
|
@ -82,7 +82,7 @@ function registerComposables(resolvePath: any, moduleOptions: ModuleOptions) {
|
||||||
from: resolvePath({ name, as: item.as, from: item.from, type: 'composable' })
|
from: resolvePath({ name, as: item.as, from: item.from, type: 'composable' })
|
||||||
};
|
};
|
||||||
|
|
||||||
addImports(opt);
|
moduleOptions.autoImport && addImports(opt);
|
||||||
|
|
||||||
return opt;
|
return opt;
|
||||||
});
|
});
|
||||||
|
@ -111,7 +111,7 @@ function registerStyles(resolvePath: any, registered: any, moduleOptions: Module
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!moduleOptions.autoImport && !options?.unstyled) {
|
if (moduleOptions.autoImport && !options?.unstyled) {
|
||||||
if (isNotEmpty(registered?.components)) {
|
if (isNotEmpty(registered?.components)) {
|
||||||
styles.push({
|
styles.push({
|
||||||
name: 'BaseComponentStyle',
|
name: 'BaseComponentStyle',
|
||||||
|
|
Loading…
Reference in New Issue