@newbie111
- During development, keep your raw, uncompiled CSS and JS files in the resources/css and resources/js directories, respectively.
- Use Vite for compiling and bundling these assets. Vite will place the compiled assets in the public directory.
Include these compiled assets in your Blade templates using the @vite directive.
- This setup ensures that your development process is streamlined (with assets being automatically compiled and refreshed as you work) and that your application serves optimized assets to your users.
To ensure Vite places the compiled assets in your desired location, you should check and configure your vite.config.js file accordingly. Here's a very basic example of what the configuration might look like if you're customizing the output directory:
// vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel([
'resources/css/app.css',
'resources/js/app.js',
]),
],
build: {
outDir: 'public/build',
},
});
testing with Vite: While developing, you might use commands like npm run dev or vite to start a development server that provides features like hot module replacement (HMR). These commands are great for a development environment because they compile your assets on-the-fly and refresh your browser automatically as you make changes.
Preparing for Production: When your development and testing phases are complete, and you're ready to prepare your application for a production environment, you should use the command npm run build.