简体   繁体   中英

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/

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. But this app in one page. one link all request is 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

.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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