symfony / webpack-encore

A simple but powerful API for processing & compiling assets built around Webpack
https://symfony.com/doc/current/frontend.html
MIT License
2.23k stars 197 forks source link

How to load encore compiled js files in third party app #1271

Open maciejregula opened 2 months ago

maciejregula commented 2 months ago

Hi,

I have application where some js files need to be loaded by third party app so there is no "encore_entry_script_tags" function to load js files. I have two entrypoints in my encore configuration:

    builds:
        admin: '%kernel.project_dir%/public/admin/build'
        front: '%kernel.project_dir%/public/front/build'

My admin app (REACT + SYMFONY) uses the admin build so I can load my js builds via "encore_entry_script_tags". However, the front build should be loaded by a third-party application and there is not possible to use "encore_entry_script_tags". Is it possible to keep encore build in one js file with specific given name so it can be easily loaded via regular <script type="text/javascript" src"" /> ?

stof commented 2 weeks ago

It is possible:

stof commented 2 weeks ago

Alternatively, you could keep the versioning of assets for the build and build a controller in your Symfony application that would redirect from /front.js to the appropriate versioned asset (allowing to keep a long cache for the versioned asset and all dynamic chunks of the build)