在Linux上,Laravel可以通过使用Laravel Mix和BrowserSync来实现代码热更新。以下是具体步骤:
安装Node.js和NPM:首先确保你的Linux系统已经安装了Node.js和NPM。如果没有,请访问Node.js官网下载并安装。
安装Laravel Mix:在你的Laravel项目根目录下,运行以下命令来全局安装Laravel Mix:
npm install laravel-mix --save-dev
npm install browser-sync browser-sync-webpack-plugin --save-dev
webpack.mix.js文件,添加以下内容:const mix = require('laravel-mix');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
//
]);
mix.webpackConfig({
plugins: [
new BrowserSyncPlugin({
host: 'localhost',
port: 3000,
proxy: 'your-app-domain.test' // 替换为你的应用域名
})
]
});
npm run hot
现在,当你修改项目中的任何文件时,浏览器将自动刷新以显示最新的更改。这将大大提高你的开发效率。