@dynect/base 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/module.ts +46 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynect/base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "Reusable Nuxt base module — components, composables, utils, plugins and i18n from the Dynect design system.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -81,8 +81,11 @@
|
|
|
81
81
|
"reka-ui": "^2.9.7",
|
|
82
82
|
"shadcn-nuxt": "^2.6.2",
|
|
83
83
|
"signature_pad": "^5.1.3",
|
|
84
|
+
"@tailwindcss/vite": "^4.3.0",
|
|
84
85
|
"tailwind-merge": "^3.5.0",
|
|
86
|
+
"tailwindcss": "^4.3.0",
|
|
85
87
|
"tailwindcss-animate": "^1.0.7",
|
|
88
|
+
"tw-animate-css": "^1.4.0",
|
|
86
89
|
"vaul-vue": "^0.4.1",
|
|
87
90
|
"vee-validate": "^4.15.1",
|
|
88
91
|
"vue-echarts": "^8.0.1",
|
|
@@ -97,10 +100,7 @@
|
|
|
97
100
|
"@iconify-json/heroicons": "^1.2.3",
|
|
98
101
|
"@iconify-json/lucide": "^1.2.106",
|
|
99
102
|
"@iconify-json/mdi": "^1.2.3",
|
|
100
|
-
"@tailwindcss/vite": "^4.3.0",
|
|
101
103
|
"@types/node": "^25.6.2",
|
|
102
|
-
"tailwindcss": "^4.3.0",
|
|
103
|
-
"tw-animate-css": "^1.4.0",
|
|
104
104
|
"typescript": "^6.0.3"
|
|
105
105
|
}
|
|
106
106
|
}
|
package/src/module.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { addComponentsDir, addImports, addImportsDir, addPlugin, createResolver, defineNuxtModule, installModule } from '@nuxt/kit';
|
|
2
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
3
|
+
import { defu } from 'defu';
|
|
2
4
|
import { existsSync } from 'node:fs';
|
|
3
5
|
import { join } from 'node:path';
|
|
4
6
|
|
|
@@ -24,6 +26,8 @@ export interface DynectBaseOptions {
|
|
|
24
26
|
/** Enable SSR width plugin. Default: true */
|
|
25
27
|
ssrWidth?: boolean;
|
|
26
28
|
};
|
|
29
|
+
/** Auto-register @tailwindcss/vite Vite plugin. Set false to disable (e.g. if already configured in nuxt.config). Default: true */
|
|
30
|
+
tailwind?: boolean;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
const DIR_CONFIGS: Record<string, { prefix: string }> = {
|
|
@@ -42,6 +46,7 @@ export default defineNuxtModule<DynectBaseOptions>({
|
|
|
42
46
|
defaults: {
|
|
43
47
|
dirs: ['dynect', 'ui', 'base', 'chart'],
|
|
44
48
|
global: true,
|
|
49
|
+
tailwind: true,
|
|
45
50
|
veeValidate: {},
|
|
46
51
|
colorMode: {},
|
|
47
52
|
i18n: {},
|
|
@@ -69,28 +74,56 @@ export default defineNuxtModule<DynectBaseOptions>({
|
|
|
69
74
|
|
|
70
75
|
const srcDir = nuxt.options.srcDir;
|
|
71
76
|
|
|
72
|
-
// @/lib/utils
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// @/components/ui/* → runtime/components/ui/*
|
|
79
|
-
// Must run BEFORE @ is resolved, so we use a regex alias in vite:extendConfig.
|
|
80
|
-
// Only applied when the consuming app has no own components/ui directory.
|
|
81
|
-
if (isStandalone && !existsSync(join(srcDir, 'components', 'ui'))) {
|
|
77
|
+
// In standalone mode, intercept @/lib/utils and @/components/ui BEFORE Vite
|
|
78
|
+
// expands the @ alias to srcDir. nuxt.options.alias cannot do this because
|
|
79
|
+
// Vite resolves @ → srcDir in a single pass and never checks aliases again.
|
|
80
|
+
// We prepend regex aliases via vite:extendConfig so they fire first.
|
|
81
|
+
if (isStandalone) {
|
|
82
82
|
const uiRuntimePath = join(runtimeComponentsDir, 'ui');
|
|
83
|
+
const libUtilsRuntimePath = resolver.resolve('./runtime/lib/utils');
|
|
84
|
+
|
|
85
|
+
// Only redirect @/lib/utils when the consuming app has no own lib/utils
|
|
86
|
+
const hasOwnLibUtils = existsSync(join(srcDir, 'lib', 'utils.ts'));
|
|
87
|
+
// Only redirect @/components/ui when the consuming app has no own components/ui
|
|
88
|
+
const hasOwnComponentsUi = existsSync(join(srcDir, 'components', 'ui'));
|
|
83
89
|
|
|
84
90
|
nuxt.hook('vite:extendConfig', (config) => {
|
|
85
91
|
config.resolve ??= {};
|
|
86
92
|
|
|
87
|
-
const
|
|
93
|
+
const entries: { find: RegExp; replacement: string }[] = [];
|
|
94
|
+
|
|
95
|
+
if (!hasOwnComponentsUi) {
|
|
96
|
+
entries.push({ find: /^[@~]\/components\/ui/, replacement: uiRuntimePath });
|
|
97
|
+
}
|
|
98
|
+
if (!hasOwnLibUtils) {
|
|
99
|
+
entries.push({ find: /^[@~]\/lib\/utils/, replacement: libUtilsRuntimePath });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (entries.length === 0) return;
|
|
88
103
|
|
|
89
104
|
if (Array.isArray(config.resolve.alias)) {
|
|
90
|
-
config.resolve.alias.unshift(
|
|
105
|
+
config.resolve.alias.unshift(...entries);
|
|
91
106
|
} else {
|
|
92
107
|
const existing = config.resolve.alias ?? {};
|
|
93
|
-
config.resolve.alias = [
|
|
108
|
+
config.resolve.alias = [
|
|
109
|
+
...entries,
|
|
110
|
+
...Object.entries(existing).map(([find, replacement]) => ({ find, replacement })),
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ── Tailwind CSS v4 ──────────────────────────────────────────────────────
|
|
117
|
+
// Add @tailwindcss/vite plugin unless disabled or already present.
|
|
118
|
+
// "Already present" check: look for any plugin named @tailwindcss/vite:*
|
|
119
|
+
// so we don't double-process if the consuming app added it manually.
|
|
120
|
+
if (options.tailwind !== false) {
|
|
121
|
+
nuxt.hook('vite:extendConfig', (config) => {
|
|
122
|
+
const c = config as any;
|
|
123
|
+
const flat = ([...(c.plugins ?? [])]).flat().filter(Boolean) as { name?: string }[];
|
|
124
|
+
const alreadyAdded = flat.some((p) => typeof p.name === 'string' && p.name.startsWith('@tailwindcss/vite'));
|
|
125
|
+
if (!alreadyAdded) {
|
|
126
|
+
c.plugins = [...(c.plugins ?? []), tailwindcss()];
|
|
94
127
|
}
|
|
95
128
|
});
|
|
96
129
|
}
|