在laravel5.3以前 , 前端工程化依赖 gulp ,在5.4的时候laravel为咱们带来了全新的前端工具mix
本节记录从0到看到mix打包完成 ,laravel渲染出helloworld阅读本节前提 : 须要有laravel和vue使用经验或对先后端工程化有清晰的认知javascript
1 . 安装laravelcss
composer create-project laravel/laravel learn-mix
2 . 安装前端依赖html
cd learn-mix ; npm install
3 . 安装vue-router前端
npm install vue-router
新建 /resources/assets/js/routes.js ,并写入如下内容
import VueRouter from 'vue-router'; let routes = [ { path: '/', component: require('./components/你的组件名字') } ]; export default new VueRouter({ routes });
2 . 导入路由vue
修改 /resources/assets/js/app.js
// 导入路由包 import VueRouter from 'vue-router'; // use Vue.use(VueRouter); // 导入路由文件 import routes from './routes.js'; const app = new Vue({ el: '#app', // 使用路由 router: routes });
3 . 编译java
回到根目录
npm run dev npm run watch # 任选其一
4 . 修改laravel默认的 / 路由指向的welcome模板laravel
<!doctype html> <html lang="{{ app()->getLocale() }}"> <head> <!--导入编译好的CSS--> <link rel="stylesheet" href="/css/app.css"> <!--导入CSRF_TOKEN--> <meta name="csrf-token" content="{{ csrf_token() }}"/> </head> <body> <div id="app"> <router-view></router-view> </div> <!--导入编译好的JS--> <script src="/js/app.js"></script> </body> </html>