Home  >  Article  >  PHP Framework  >  Detailed explanation of Laravel front-end engineering mix

Detailed explanation of Laravel front-end engineering mix

藏色散人
藏色散人forward
2021-04-13 14:05:431944browse

The following is the tutorial column of laravel to introduce you to the mix of Laravel front-end engineering. I hope it will be helpful to friends in need!

Detailed explanation of Laravel front-end engineering mix

Before laravel5.3, front-end engineering relied on gulp, and in 5.4 At that time, laravel brought us a new front-end tool mix
This section records from 0 to seeing mix packaging completed, laravel renders helloworld

Prerequisites for reading this section: Requires experience in using laravel and vue Or have a clear understanding of front-end and back-end engineering

Install

1. Install laravel

composer create-project laravel/laravel learn-mix

2. Install front-end dependencies

cd learn-mix ; npm install

3. Install vue-router

npm install vue-router

Configuration

  1. Create routing file
New/resources/assets/js/routes.js, And write the following content
import VueRouter from 'vue-router';

let routes = [
    {
        path: '/',
        component: require('./components/你的组件名字')
    }
];

export default new VueRouter({
    routes
});

2. Import routing

Modify/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. Compile

back Go to the root directory
npm run dev 
npm run watch 
# 任选其一

4. Modify the welcome template pointed by laravel's default / route

<!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>
<p id="app">
    <router-view></router-view>
</p>
<!--导入编译好的JS-->
<script src="/js/app.js"></script>
</body>
</html>

Visit 127.0.0.1 and you will see the laravel-mix welcome page, END

Related recommendations: The latest five Laravel video tutorials

The above is the detailed content of Detailed explanation of Laravel front-end engineering mix. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete