问题描述
我尝试设置资产的相对路径
.setPublicPath('build/')
但是当编译时我得到
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
并生成链接
{% block javascripts %}
{{ encore_entry_script_tags('app') }}
{% endblock %}
并得到
<script src="/build/runtime.js" defer></script>
<script src="/build/vendors~app.js" defer></script>
<script src="/build/app.js" defer></script>
我需要构建/而不是/构建/
我有基于文件夹的应用程序的服务器,所以为什么不能像我想要的那样设置补丁。我知道当应用程序使用路由 /aa/bb/cc 这停止工作。但是这个应用程序在一页中。一个链接所有请求都是ajax。
就像消息“应该通常以“/”开头,必须替换我们添加 / 因为这对你更好......
解决方法
好的,我找到了可行的解决方案
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')
我从 env 中读取了 myAppSubdir 并且几乎是动态的。