webpack-encore .setPublicPath 相对忽略

问题描述

我尝试设置资产的相对路径

 .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 并且几乎是动态的。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...