简体   繁体   English

webpack-encore.setPublicPath 相对忽略

[英]webpack-encore .setPublicPath relative ignored

I try set relative path to assets我尝试设置资产的相对路径

 .setPublicPath('build/')

but when compile i get但是当编译时我得到

 The value passed to setPublicPath() should *usually* start with "/" or be a full URL (http://...). If you're not sure, then you should probably change your public path and make this message disappea

and generate links并生成链接

{% block javascripts %}
    {{ encore_entry_script_tags('app') }}
{% endblock %}

and get并得到

<script src="/build/runtime.js" defer></script>
<script src="/build/vendors~app.js" defer></script>
<script src="/build/app.js" defer></script>

I need build/ not /build/我需要构建/而不是/build/

I have server with folder based apps so why cannot setup patch like I want.我有基于文件夹的应用程序的服务器,所以为什么不能像我想要的那样设置补丁。 I know that when app use routing /aa/bb/cc this stops working.我知道当应用程序使用路由 /aa/bb/cc 这停止工作。 But this app in one page.但是这个应用程序在一页中。 one link all request is ajax.一个链接所有请求是 ajax。

Like in message "should usually start with "/" " should must by replaced we add / because this is better for you...就像在消息中“通常应该以“/”开头”应该替换我们添加 / 因为这对你更好......

Ok i found working solution好的,我找到了可行的解决方案

https://symfony.com/doc/current/frontend/encore/faq.html https://symfony.com/doc/current/frontend/encore/faq.html

.setOutputPath('public/build/')
- .setPublicPath('/build')
+ // this is your *true* public path
+ .setPublicPath('/myAppSubdir/build')
+ // this is now needed so that your manifest.json keys are still `build/foo.js`
+ // (which is a file that's used by Symfony's `asset()` function)
+ .setManifestKeyPrefix('build')

i read myAppSubdir from env and is almost dynamic.我从 env 读取 myAppSubdir 并且几乎是动态的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM