A basic showcase of how to implement auto-import files in an InertiaJS (Vue) project with Laravel.
This setup allows you to automatically import Vue components, composables, and utilities in your InertiaJS project without manually specifying imports in each file.
Configures Vite to automatically scan and import components, composables, and utilities. This file integrates the auto-import plugin to handle component registration.
Lists the dependencies required for auto-importing functionality, including unplugin-vue-components
and unplugin-auto-import
. Make sure these plugins are installed.
Ensures TypeScript recognizes the auto-imported components and functions, enabling full type support and IDE autocompletion.
This folder contains files generated by Vite for auto-importing. These files manage the internal mapping of components, making them available globally in your project.
-
Install Required Packages
npm install -D unplugin-vue-components unplugin-auto-import
-
Configure Vite Modify your
vite.config.js
to include the auto-import setup:import Components from "unplugin-vue-components/vite"; import AutoImport from "unplugin-auto-import/vite"; export default defineConfig({ plugins: [ //... Components({ dirs: ["resources/js/Components"], extensions: ["vue"], deep: true, dts: ".inertia/components.d.ts", directoryAsNamespace: true, resolvers: [ (name) => { if (name.startsWith("Inertia")) { return { name, importName: name.replace("Inertia", ""), path: "@inertiajs/vue3", }; } }, ], }), AutoImport({ imports: [ "vue", { "@inertiajs/vue3": [ "usePage", "useRemember", "useForm", "router", ], }, ], dirs: ["resources/js/Composables", "resources/js/Utils"], dts: ".inertia/imports.d.ts", }), ], });
Update
tsconfig.json
Add the generated type declarations to TypeScript configuration:{ "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./resources/js/*"], }, "types": [ "vite/client", "vue", "./.inertia/index.d.ts" ] }, "include": [ // ... ".inertia/index.d.ts", ".inertia/shims-vue.d.ts", ] }
Run Your Project Start the development server to generate the auto-import files:
npm run dev
After completing the setup, you can use your components and composables without explicitly importing them.
inertiajs-autoimporting-temp's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.