在 laravel 中将 public 文件夹重命名为 public_html

Rename the public folder to public_html in laravel

我在 project.In 我的项目中使用 Laravel 和 Vuejs,我将 public 文件夹的名称更改为 public_html。当我 运行 “npm 运行 watch” 命令时,public 文件夹再次创建,这对我来说是个问题。

在 AppServiceProvider 中

class AppServiceProvider extends ServiceProvider
   {
   /**
   * Register any application services.
   *
   * @return void
   */
  public function register()
   {
    $this->app->bind('path.public',function (){
        return base_path().'/public_html';
    });
   }

  /**
   * Bootstrap any application services.
   *
   * @return void
   */
   public function boot()
   {
    //
   }
 }

在我的 server.php 代码中:

<?php

/**
* Laravel - A PHP Framework For Web Artisans
*
* @package  Laravel
* @author   Taylor Otwell <taylor@laravel.com>
*/

$uri = urldecode(
  parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

 // This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel 
// application without having installed a "real" web server software here.
 if ($uri !== '/' && file_exists(__DIR__ . '/public_html' . $uri)) {
  return false;
 }

 require_once __DIR__ . '/public_html/index.php';

并在 webpack.mix.js

const mix = require('laravel-mix');

 /*
 |-------------------------------------------------------------
 | Mix Asset Management
 |------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build 
    steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

  mix.js('resources/js/app.js', 'public_html/js')
    .sass('resources/sass/app.scss', 'public_html/css');

有谁知道如何解决此问题以便不重新创建 public 文件夹?

您可以通过在 webpack.mix.js

中调用 mix.setPublicPath("your-public-path") 来实现