Laravel x Vite / Kuro Hsu @ PHP 也有 Day #60
Kuro Hsu @ PHP 也有 Day #602021/08/05Laravel x Vite
View Slide
Kuro HsuFront-End DeveloperOrganizers of Vue.js Taiwan(Vue.tw)https://kuro.tw[email protected]@kurotanshi
Vite 是什麼vite⚡ 發音 /vit/ ,是法語中「快速」的意思由 Vue.js 的作者 Evan You 所開發快速啟動、即時更新的前端 「開發工具」不只 親兒子 Vue, React 也能用!https://github.com/vitejs/vite
實際對比: 以 React Create App 為例Link
Vite 為什麼這麼快
以 Bundle 為基礎 (webpack)
以 ES Module 為基礎 (vite、snowpack)
橫向對比
更多相關細節[MOPCON 2020] vite: Make web dev fast again
今日重點 - Vite ❤️Laravel
基本需求Laravel: PHP 7.4+Vite: Node 12+開發用 瀏覽器需支援 ES Module若需支援舊版瀏覽器 ,須另外安裝 @vitejs/plugin-legacy
開始與起步首先要有一個 laravel 專案:切換到專案目錄,並執行:1 $ composer create-project laravel/laravel example-app1 $ npx apply laravel:vite
手動處理或者也可以自行處理:1 #手動移除 laravel-mix2 rm webpack.mix.js3 yarn remove laravel-mix1 #安裝必要套件,此步驟不可省略!2 composer require innocenzi/laravel-vite3 yarn add vite laravel-vite --dev
設定編輯 vite.config.ts 檔案1 // vite.config.ts2 import { defineConfig } from 'laravel-vite'3 import vue from '@vitejs/plugin-vue'45 export default defineConfig()6 .withPlugin(vue)7 .merge({8 // Your own Vite options9 })
設定編輯 package.json 檔案1 // package.json2 "scripts": {3 "dev": "vite",4 "build": "vite build",5 "serve": "vite preview"6 },3 "dev": "php artisan serve & vite", //同時啟動 artisan serve與 vite1 // package.json2 "scripts": {4 "build": "vite build",5 "serve": "vite preview"6 },
這是用來更新靜態檔的 vite 服務注意,這才是開發用網頁伺服器
Hello Vite!
更多資訊Laravel ViteViteJSvite2: Make Web Dev Fast Again & Again