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 198 forks source link

How can I access the output files without Symfony? #676

Open thomaskanzig opened 4 years ago

thomaskanzig commented 4 years ago

Hi guys,

I have add @symfony/webpack-encore but I don't use Symfony. I just a normally project with PHP pure. I define too my config file webpack.config.js in my root path with all necessary settings.

The question is how can I access the output files in my html ou php file?

# Define my output file.
.addEntry('main', './assets/js/main.js')

...and become main.5660ea39.js with a posfix hash and I can't define a fix url in my <head>.

Help please.

jfcherng commented 4 years ago

manifest.json is the naming map. You can parse it to get the versioned file path.

Or, you can force disable the versioning by Encore.enableVersioning(false). But in that case, you may suffer from browser's caching mechanism.

Lyrkan commented 4 years ago

Hey @thomaskanzig,

It depends on the content of your webpack.config.js :)

Using enableVersioning() Using splitEntryChunks() How to
No No Nothing needed, you can directly call generated assets using their name
Yes No You'll need to write some code that reads the manifest.json file to retrieve the generated names
Yes or No Yes You'll need to write some code that reads the entrypoints.json file to retrieve which file(s) should be added for a given entrypoint

Note that if you call enableSingleRuntimeChunk() you'll also need to add the generated runtime.js file (that can also be versioned) to your page(s).