Ask Your Question
4

What are the steps to create a Laravel 9 project utilizing Vuetify and Vite?

asked 2023-07-07 01:17:06 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-07-07 01:43:02 +0000

nofretete gravatar image
  1. Install Laravel 9 using Composer: composer create-project --prefer-dist laravel/laravel my-project-name
  2. Navigate to the project directory and install Vuetify using npm: cd my-project-name npm install vuetify
  3. Install Vite in the project using npm: npm install -D vite
  4. Create a new folder named client in the project root directory for the Vue.js code: mkdir client
  5. Create a new file named vite.config.js in the project root directory and add the following code to enable Vue.js with Vite:

    import { defineConfig } from 'vite';
    import vue from '@vitejs/plugin-vue';
    
    export default defineConfig({
     plugins: [vue()],
    });
    
  6. In the client folder, create a new file named main.js and add the following code to activate Vuetify:

    import { createApp } from 'vue';
    import App from './App.vue';
    import 'vuetify/dist/vuetify.min.css';
    import { createVuetify } from 'vuetify';
    
    const vuetify = createVuetify({
     theme: {
       themes: {
         light: {
           primary: '#4CAF50',
           secondary: '#9C27b0',
           accent: '#8c9eff',
           error: '#b71c1c',
         },
       },
     },
    });
    
    createApp(App).use(vuetify).mount('#app');
    
  7. In the client folder, create a new file named App.vue and add the following code:

    <template>
     <v-app>
       <v-main>
         <router-view></router-view>
       </v-main>
     </v-app>
    </template>
    
    <script>
    export default {
     name: 'App',
    };
    </script>
    
    <style>
    </style>
    
  8. In the client folder, create a new file named router.js and add the following code to enable Vue Router:

    import { createRouter, createWebHistory } from 'vue-router';
    
    const routes = [
     {
       path: '/',
       name: 'Home',
       component: () => import(/* webpackChunkName: "about" */ './views/Home.vue'),
     },
     {
       path: '/about',
       name: 'About',
       component: () => import(/* webpackChunkName: "about" */ './views/About.vue'),
     },
    ];
    
    const router = createRouter({
     history: createWebHistory(),
     routes,
    });
    
    export default router;
    
  9. In the client folder, create a new file named views/Home.vue and add the following code:

    <template>
     <h1>Home</h1>
    </template>
    
    <script>
    export default {
     name: 'Home',
    };
    </script>
    
    <style>
    </style>
    
  10. In the client folder, create a new file named views/About.vue and add the following code:

    <template>
      <h1>About</h1>
    </template>
    
    <script>
    export default {
      name: 'About',
    };
    </script>
    
    <style>
    </style>
    
  11. Modify the webpack.mix.js file in the project root directory to add the Vite build process, Vuetify stylesheet and Vue.js libraries:

    const mix = require('laravel-mix');
    
    mix.js('resources/js/app.js', 'public/js')
       .sass('resources/sass/app.scss', 'public/css')
       .webpackConfig({
          devServer: {
               proxy: 'http://localhost:8000',
               watchFiles: ['client/**/*'],
               open: true,
          },
        })
       .vuetify('vuetify-loader')
       .vue({ version: '2.6.14' })
       .version();
    
  12. Run the Vite development server by typing the following command: npm run dev
  13. Open the browser and navigate to http://localhost:3000/ to view the running Laravel 9 project utilizing Vuetify and Vite.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-07 01:17:06 +0000

Seen: 11 times

Last updated: Jul 07 '23