@hardimpactdev/craft-ui 0.0.4 → 0.0.5

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.
@@ -0,0 +1,26 @@
1
+ import { UserConfig } from 'vite';
2
+ interface CraftConfigOptions {
3
+ laravel?: {
4
+ input: string | string[];
5
+ publicDirectory?: string;
6
+ buildDirectory?: string;
7
+ ssr?: string | string[];
8
+ ssrOutputDirectory?: string;
9
+ refresh?: boolean | string | string[];
10
+ hotFile?: string;
11
+ detectTls?: string | boolean;
12
+ valetTls?: string | boolean;
13
+ transformOnServe?: (code: string, url: string) => string;
14
+ };
15
+ }
16
+ export declare function defineCraftConfig(options?: CraftConfigOptions): UserConfig;
17
+ /**
18
+ * Craft Vite plugin that provides virtual module for app initialization
19
+ */
20
+ export declare function craft(): {
21
+ name: string;
22
+ enforce: "pre";
23
+ resolveId(id: string): "virtual:craft" | undefined;
24
+ load(id: string): "\n import { createInertiaApp } from \"@inertiajs/vue3\";\n import { resolvePageComponent } from \"laravel-vite-plugin/inertia-helpers\";\n import { createApp, h } from \"vue\";\n import { i18n } from \"@hardimpactdev/craft-ui\";\n import { TooltipProvider } from \"reka-ui\";\n\n const appName = import.meta.env.VITE_APP_NAME || \"Laravel\";\n\n export function initializeCraft(options) {\n const { enhanceVue, layouts } = options || {};\n\n return createInertiaApp({\n title: (title) => `${title} - ${appName}`,\n resolve: (name) => {\n const pages = import.meta.glob('/resources/js/pages/**/*.vue', {\n eager: true,\n });\n\n const page = pages[`/resources/js/pages/${name}.vue`];\n\n let defaultLayout = undefined;\n\n if (layouts) {\n Object.entries(layouts).forEach(([key, value]) => {\n if(name.startsWith(key)) {\n defaultLayout = value;\n }\n\n if(!defaultLayout && layouts.default) {\n defaultLayout = layouts.default;\n }\n });\n }\n\n if(!page) {\n const errorMessage = `Page not found: ${name}.vue`;\n\n console.error(`[Inertia] ${errorMessage}`);\n }\n\n page.default.layout = defaultLayout;\n return page;\n },\n setup({ el, App, props, plugin }) {\n // Get the language files and transform the paths\n const langGlob = import.meta.glob(\"/lang/*.json\", { eager: true });\n\n // Transform absolute paths to relative paths expected by i18n\n const transformedLangs = {};\n Object.entries(langGlob).forEach(([absolutePath, module]) => {\n // Convert \"/lang/en.json\" to \"../../lang/en.json\"\n const relativePath = absolutePath.replace('/lang/', '../../lang/');\n transformedLangs[relativePath] = module;\n });\n\n let app = createApp({ render: () => h(TooltipProvider, null, () => h(App, props)) })\n .use(plugin)\n .use(i18n, {\n langs: transformedLangs,\n changeLanguageRoute: '/change-language',\n });\n\n if (enhanceVue) {\n app = enhanceVue(app);\n }\n\n app.mount(el);\n },\n progress: {\n includeCSS: false,\n },\n });\n }" | undefined;
25
+ };
26
+ export {};
@@ -1,19 +1,29 @@
1
+ function defineCraftConfig(options = {}) {
2
+ const laravelConfig = options.laravel ?? {
3
+ input: ["resources/js/app.ts"]
4
+ };
5
+ return {
6
+ plugins: [
7
+ // These will be dynamically imported by the consuming app
8
+ // We provide the config structure, they provide the actual plugins
9
+ ],
10
+ optimizeDeps: {
11
+ exclude: [
12
+ "@hardimpactdev/craft-ui",
13
+ "@tailwindcss/vite",
14
+ "laravel-vue-i18n/vite"
15
+ ]
16
+ },
17
+ // Store laravel config for the consuming app to use
18
+ define: {
19
+ __CRAFT_LARAVEL_CONFIG__: JSON.stringify(laravelConfig)
20
+ }
21
+ };
22
+ }
1
23
  function craft() {
2
- const plugins = [];
3
- plugins.push({
24
+ return {
4
25
  name: "craft",
5
26
  enforce: "pre",
6
- config() {
7
- return {
8
- optimizeDeps: {
9
- exclude: [
10
- "@hardimpactdev/craft-ui",
11
- "@tailwindcss/vite",
12
- "laravel-vue-i18n/vite"
13
- ]
14
- }
15
- };
16
- },
17
27
  resolveId(id) {
18
28
  if (id === "virtual:craft") {
19
29
  return id;
@@ -97,9 +107,9 @@ function craft() {
97
107
  }`;
98
108
  }
99
109
  }
100
- });
101
- return plugins;
110
+ };
102
111
  }
103
112
  export {
104
- craft
113
+ craft,
114
+ defineCraftConfig
105
115
  };
@@ -1,27 +1,58 @@
1
- export function craft() {
2
- const plugins = [];
1
+ import type { UserConfig } from 'vite'
2
+
3
+ interface CraftConfigOptions {
4
+ laravel?: {
5
+ input: string | string[]
6
+ publicDirectory?: string
7
+ buildDirectory?: string
8
+ ssr?: string | string[]
9
+ ssrOutputDirectory?: string
10
+ refresh?: boolean | string | string[]
11
+ hotFile?: string
12
+ detectTls?: string | boolean
13
+ valetTls?: string | boolean
14
+ transformOnServe?: (code: string, url: string) => string
15
+ }
16
+ }
3
17
 
4
- // Core plugin
5
- plugins.push({
6
- name: 'craft',
7
- enforce: 'pre',
8
- config() {
9
- return {
10
- optimizeDeps: {
11
- exclude: [
12
- '@hardimpactdev/craft-ui',
13
- '@tailwindcss/vite',
14
- 'laravel-vue-i18n/vite'
15
- ]
16
- }
17
- };
18
+ export function defineCraftConfig(options: CraftConfigOptions = {}): UserConfig {
19
+ const laravelConfig = options.laravel ?? {
20
+ input: ['resources/js/app.ts'],
21
+ }
22
+
23
+ return {
24
+ plugins: [
25
+ // These will be dynamically imported by the consuming app
26
+ // We provide the config structure, they provide the actual plugins
27
+ ],
28
+ optimizeDeps: {
29
+ exclude: [
30
+ '@hardimpactdev/craft-ui',
31
+ '@tailwindcss/vite',
32
+ 'laravel-vue-i18n/vite'
33
+ ]
18
34
  },
35
+ // Store laravel config for the consuming app to use
36
+ define: {
37
+ __CRAFT_LARAVEL_CONFIG__: JSON.stringify(laravelConfig)
38
+ }
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Craft Vite plugin that provides virtual module for app initialization
44
+ */
45
+ export function craft() {
46
+ return {
47
+ name: 'craft',
48
+ enforce: 'pre' as const,
19
49
 
20
50
  resolveId(id: string) {
21
51
  if (id === 'virtual:craft') {
22
- return id;
52
+ return id
23
53
  }
24
54
  },
55
+
25
56
  load(id: string) {
26
57
  if (id === 'virtual:craft') {
27
58
  return `
@@ -100,10 +131,5 @@ export function craft() {
100
131
  }`;
101
132
  }
102
133
  },
103
- });
104
-
105
- // Add other plugins
106
- // plugins.push(plugin());
107
-
108
- return plugins;
134
+ }
109
135
  }
package/package.json CHANGED
@@ -51,7 +51,7 @@
51
51
  "types": "./dist/src/vite/defineCraftConfig.d.ts"
52
52
  }
53
53
  },
54
- "version": "0.0.4",
54
+ "version": "0.0.5",
55
55
  "type": "module",
56
56
  "scripts": {
57
57
  "dev": "vite",
@@ -1,4 +0,0 @@
1
- export declare function craft(): {
2
- name: string;
3
- enforce: string;
4
- }[];