如何在 Laravel Mix 中将公共路径更改为包含下划线的内容?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42051576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:16:25  来源:igfitidea点击:

How can I change the public path to something containing an underscore in Laravel Mix?

phplaravellaravel-elixirlaravel-5.4laravel-mix

提问by Mike

In Laravel 5.4 Mix was introduced to compile assets and maintain the asset pipeline. Mix defaults to your public directory being named public. In many cases, including mine, my public directory is called something else. In my case, it's public_html.

在 Laravel 5.4 中引入了 Mix 来编译资产和维护资产管道。Mix 默认为您的公共目录命名为public。在许多情况下,包括我的,我的公共目录被称为别的东西。就我而言,它是public_html.

How can I change the public directory where assets are compiled to?

如何更改资产编译到的公共目录?

I have tried changing the paths within webpack.min.jsto:

我尝试将路径更改webpack.min.js为:

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

Unfortunately this compiles to:

不幸的是,这编译为:

- public
|- _html
|-- assets
|--- css
|--- js
|- fonts

In Laravel 5.3 and Elixir this was as simple as:

在 Laravel 5.3 和 Elixir 中,这很简单:

elixir.config.publicPath = 'public_html/assets';

I have checked Mix's config file, but can't see anything obvious here.

我已经检查了 Mix 的配置文件,但在这里看不到任何明显的东西。

Please note: this is Laravel Mix, the npm package, so it's nothing to do with amends in the index.phpfile.

请注意:这是 Laravel Mix,npm 包,因此与index.php文件中的修改无关。

回答by Mike

There is an undocumented (I believe) method called setPublicPath. You can then omit the public path from the output. setPublicPathplays nicely with underscores.

有一个未记录的(我相信)方法称为setPublicPath. 然后,您可以从输出中省略公共路径。 setPublicPath与下划线搭配得很好。

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

回答by musa hayta

In Laravel 5.5 I've solved like this,

在 Laravel 5.5 我已经解决了这样的问题,

mix.setPublicPath('public_html/')
    .js('resources/assets/js/app.js', 'front/js')
    .js('resources/assets/js/custom.js', 'front/js')
   .sass('resources/assets/sass/app.scss', 'front/css')
   .styles('resources/assets/css/custom.css', 'public_html/front/css/custom.css');

回答by Bashirpour

In Laravel 5.8

在 Laravel 5.8 中

mix.config.publicPath='public_html';
mix.js('resources/assets/js/app.js', 'public_html/js')
   .sass('resources/assets/sass/app.scss', 'public_html'/css');

回答by hamidteimouri

In Laravel 5.4 you can us this code:

在 Laravel 5.4 中,您可以使用以下代码:

in AppServiceProvider:

AppServiceProvider 中

public function register()
{

    $this->app->bind('path.public', function () {
        return base_path() . DIRECTORY_SEPARATOR .'public_html';
    });

}