Webpack-encore: Static assets and inheritance

Created on 1 Aug 2017  路  3Comments  路  Source: symfony/webpack-encore

Hello again fine people,

As I continue my many struggles in replacing Assetic with the new-recommended Webpack Encore, I'm faced with yet one more existential question:

How to deal with static assets, inheritance and Twig ?

I am aware of the existence of #24 and #85, this is related but not exactly the same.

Assetic had the extremely handy function of enabling us to use Symfony's inheritance system to override static assets like images.

For example I'm using a vendor bundle HelloBundle that has an image in Resources/public/img/hello.jpg.
Now I have my own bundle MyHelloBundle that inherits HelloBundle, and I also have an image in Resources/public/img/hello.jpg, that's different from the vendor's one.
This was pretty easy using Assetic and the @notation.

I have no idea how I'm supposed to replicate this with Encore since:

1: I have no idea how to get Encore to handle all of my assets (images, "required" directly in the HTML in an <img> src, for example).
2: I don't know how to tell Encore that Bundle X inherits Bundle Y and has a result I want to load the stuff from Bundle X if it exists, and if not, defaults to Bundle Y.

I know that Symfony and Webpack Encore are separate projects, but Symfony decided to drop Assetic and to recommend Encore instead, while providing no backup on how to handle most things that were handled by Assetic before...

I do know that I have the option of still using Assetic, but I want to believe in Encore and in the choices that the Symfony team made.

Most helpful comment

Hello,

That's exactly it. I'm working on a "white label" kind of architecture.
We have a few bundles that are common to each white label, and then we want to be able to customize almost every part of those bundles.

They are treated like 3rd party bundles, we require them with composer for each new install (depending on what the client asked for) and then customize to the client's needs.

I agree that Encore should stay Symfony-free, but we could probably (if it's the best/only solution) some sort of EncoreBridgeBundle in Symfony that would run using the PHP console to gather whatever information it needs from the bundle system, and then run Encore with the correct parameters ?

I've looked around for regular Webpack solutions but failed to find anything noteworthy. Also searching for anything with "asset" and "symfony" in it returns only Assetics results.

All 3 comments

Hey @Growiel!

These are great issues to open :). I think Encore gives you much more out-of-the box than Assetic does. But, there are still some situations - like this one - where you could do something in Assetic, but not in Encore. That's what we can work on :).

Can you tell me more - at a high, feature level - what you want to accomplish? I mean, are you creating re-usable bundles where you need the end-user of the bundle to be able to replace images used in the image tags? Or is it something different? The answer here is likely that we need to think about the solution differently. I don't think (yet) that Encore should be made aware of Symfony's bundles - but I'm always open :). Instead, if we can find out how the greater Webpack community would solve the same problem, then that's better.

Cheers!

Hello,

That's exactly it. I'm working on a "white label" kind of architecture.
We have a few bundles that are common to each white label, and then we want to be able to customize almost every part of those bundles.

They are treated like 3rd party bundles, we require them with composer for each new install (depending on what the client asked for) and then customize to the client's needs.

I agree that Encore should stay Symfony-free, but we could probably (if it's the best/only solution) some sort of EncoreBridgeBundle in Symfony that would run using the PHP console to gather whatever information it needs from the bundle system, and then run Encore with the correct parameters ?

I've looked around for regular Webpack solutions but failed to find anything noteworthy. Also searching for anything with "asset" and "symfony" in it returns only Assetics results.

I'm having the same problem with you guys. I don't know how which folder should I put images into if I use encore and how to config.
Are there any ideas?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iammichiel picture iammichiel  路  3Comments

BackEndTea picture BackEndTea  路  3Comments

zek0faws picture zek0faws  路  4Comments

weaverryan picture weaverryan  路  4Comments

Growiel picture Growiel  路  4Comments