-
Notifications
You must be signed in to change notification settings - Fork 463
Expand file tree
/
Copy pathmodule.ts
More file actions
76 lines (67 loc) · 2.1 KB
/
module.ts
File metadata and controls
76 lines (67 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { defineNuxtModule, addComponent, addImportsSources, installModule, addTemplate } from '@nuxt/kit';
import * as storefrontUi from '@storefront-ui/vue';
import { defu } from 'defu';
import { join } from 'node:path';
import '@nuxtjs/tailwindcss';
// Module options TypeScript interface definition
export interface ModuleOptions {
contentPath?: string;
}
export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'storefront-ui',
configKey: 'storefrontUi',
compatibility: {
nuxt: '>=3.0.0',
},
},
// Default configuration options of the Nuxt module
defaults: {
contentPath: './node_modules/@storefront-ui/vue/**/*.{js,mjs}',
},
async setup(options, nuxt) {
const { contentPath } = options;
const customTailwindConfigTemplate = addTemplate({
filename: 'storefront-ui.tailwind.css',
write: true,
getContents: () =>
`@import "tailwindcss";
@import "@storefront-ui/vue/tailwind-config";
@plugin "@storefront-ui/typography";
@source '../**/*.vue';
@source '../node_modules/@storefront-ui/vue/**/*.vue';
`,
});
await installModule(
'@nuxtjs/tailwindcss',
defu(
{
configPath: [customTailwindConfigTemplate.dst, join(nuxt.options.rootDir, 'tailwind.config')],
config: { content: [contentPath ?? ''] },
},
nuxt.options.tailwindcss,
),
);
const components: string[] = [];
const composables: string[] = [];
Object.keys(storefrontUi).forEach((key) => {
// @ts-expect-error - if an object has a name or __name fields we consider it a Vue component instance
if (key.startsWith('Sf') && (storefrontUi[key].__name || storefrontUi[key].name)) {
components.push(key);
} else if (key.startsWith('use')) {
composables.push(key);
}
});
components.forEach((key) => {
addComponent({
name: key, // name of the component to be used in vue templates,
export: key,
filePath: `@storefront-ui/vue`,
});
});
addImportsSources({
imports: composables,
from: '@storefront-ui/vue',
});
},
});