Skip to content

Commit

Permalink
use default import for alpine components
Browse files Browse the repository at this point in the history
  • Loading branch information
yuheiy committed Oct 1, 2023
1 parent cff5fda commit 563d645
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/client/alpine-loader.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { PluginCallback } from 'alpinejs';
import type { Alpine, PluginCallback } from 'alpinejs';

export const app: PluginCallback = (Alpine) => {
export function app(Alpine: Alpine) {
const modules = import.meta.glob<PluginCallback>('./**/*.{component,store}.ts', {
import: 'plugin',
import: 'default',
eager: true,
});

for (const plugin of Object.values(modules)) {
Alpine.plugin(plugin);
}
};
}
6 changes: 3 additions & 3 deletions src/client/example.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { PluginCallback } from 'alpinejs';
import type { Alpine } from 'alpinejs';

export const plugin: PluginCallback = (Alpine) => {
export default function (Alpine: Alpine) {
Alpine.data('example', () => ({
init() {
if (import.meta.env.DEV) {
console.log('init component');
}
},
}));
};
}
6 changes: 3 additions & 3 deletions src/client/example.store.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { PluginCallback } from 'alpinejs';
import type { Alpine } from 'alpinejs';

export const plugin: PluginCallback = (Alpine) => {
export default function (Alpine: Alpine) {
Alpine.store('example', {
init() {
if (import.meta.env.DEV) {
console.log('init store');
}
},
});
};
}

0 comments on commit 563d645

Please sign in to comment.