Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to work with multiple entrypoints ? #13

Closed
shulard opened this issue Nov 7, 2018 · 11 comments
Closed

Is there a way to work with multiple entrypoints ? #13

shulard opened this issue Nov 7, 2018 · 11 comments

Comments

@shulard
Copy link
Contributor

shulard commented Nov 7, 2018

Hello !

I just tried to install this new bundle coupled with the webpack-encore v0.21.0 and faced a little issue.

In my project we have multiple Encore configuration which export assets in multiple output path. Maybe it's not the recommended way to use it but with that setup I can't use the new features because every call to twig functions will read the entry point defined in the output path.

Before that, we used the asset package feature to declare multiple packages (each one with it's own manifest.json file).

I checked the Bundle code and find that the asset packages are still used but the entrypoint.json file is always the same.

Is there a way to handle that case ?

@B-Galati
Copy link

B-Galati commented Nov 7, 2018

Hello!

FYI I have a project with pretty much the same setup and same issues (I did not try yet)

@weaverryan
Copy link
Member

Hi @shulard!

You're right that this is not currently supported. No problem - let's figure out how! First, your setup has a different outputPath for each build, correct? So you are already able to generate multiple entrypoints.json files?

If so, then the issue is just with the bundle: I think there needs to be a way to define multiple "builds", each with a unique key and different config for the output dir. So, it might look like:

webpack_encore:
    # the "default" build
    output_path: '%kernel.public_dir%/build'
    builds:
        frontend: '%kernel.public_dir%/frontend/build'

Then in Twig:

{{ encore_entry_script_tags('entry1', 'frontend') }}

{# or, really, it may need to be the third argument #}
{{ encore_entry_script_tags('entry1', null, 'frontend') }}

The tricky part is that encore_entry_script_tags() already has a 2nd argument - it's the "asset package name". That's why I listed the other option.

Thoughts?

@shulard
Copy link
Contributor Author

shulard commented Nov 8, 2018

Hello @weaverryan !

Yep I already checked the second argument for encore_entry_script_tags but I think that if we use multiple build the asset package feature is not relevant anymore (or in very specific edge cases...).

I generate multiple entrypoints.json files so your solution seems the right one. It's also compatible with the asset logic.

The only remaining questions : Is using the same logic for asset package and encore build a bit confusing for the users ? Is it relevant to support asset packages in encore twig helpers ?

@chiqui3d
Copy link

chiqui3d commented Nov 12, 2018

This option is necessary, after following this tutorial https://symfony.com/doc/current/frontend/encore/advanced-config.html#defining-multiple-webpack-configurations, I am left without being able to apply a different path for the front and admin

webpack_encore:
    # the "default" build
    output_path: 
         front :'%kernel.public_dir%/build/front'
         admin :'%kernel.public_dir%/build/admin'

@shulard
Copy link
Contributor Author

shulard commented Nov 12, 2018

Yep it's exactly the case described here. @weaverryan, if you need any help to work on that code I'll be glad to give you some time 😄.

@weaverryan
Copy link
Member

Hey! Yes, this will get done MUCH faster if you can create a PR - it’s definitely a feature that makes sense. You can ping me on Slack if you want to discuss any part :)

@bpolaszek
Copy link

Hey there! Just wanted to say I ran into the same issue when trying to upgrade from encore 0.19 to 0.22. There are now new files (entrypoints.json in addition to manifest.json, runtime.js) I don't completely understand the purpose, and it looks that the Twig functions provided by the bundle are required to make things work, but it doesn't on multiple configuration. I think I'll rollback until this feature is supported.
Thanks!

weaverryan added a commit that referenced this issue Dec 20, 2018
… each of them. (shulard)

This PR was squashed before being merged into the master branch (closes #17).

Discussion
----------

Allow to define multiple entrypoints and load assets from each of them.

This PR is added to fix the issue #13. With that new code, you can configure your project like this :

```yaml
webpack_encore:
    # the "default" build
    output_path: '%kernel.public_dir%/build'
    builds:
        frontend: '%kernel.public_dir%/frontend/build'
```

Then in your Twig template :

```twig
{{ encore_entry_script_tags('entry1', 'frontend') }}
```

Commits
-------

0f3134b Add test regarding EntrypointLookupCollection.
a238fe7 Handle the new Entrypoint collection to render paths.
2c38514 Create a new exception when the Entrypoint is not defined.
59bbd29 Update extension to load entrypoint build path.
0f69516 Add an EntrypointLookupCollection.
ebe61d9 Allow to define a list of entrypoints to be used in the project.
@chiqui3d
Copy link

chiqui3d commented Jan 9, 2019

Hello, is there anything new?

@shulard
Copy link
Contributor Author

shulard commented Jan 9, 2019

The PR was merged (cf #17) but there is no official release for the moment.

@berrymore
Copy link

Hello, @shulard

How did you deal with static files like (images, videos) in multiple layouts? Documentation says that we need to use assets which uses json_manifest_path parameter as a path to the manifest.json.

Maybe it would be a good idea to add something like encore_entry_static_file('images/logo.png', 'my_layout') and it will return something like /public/build/my_layout/images/logo.e0434341.png

Also it would be helpful to add something like encore_default_build (like trans_default_domain) to set "default" build for entire template.

@shulard
Copy link
Contributor Author

shulard commented Jan 15, 2019

Hello @berrymore !

You are right, it's not currently possible to retrieve files which are not CSS or JS. Using the Asset component will just allow you to control URL and access path for these assets, but only for the one that can be retrieved from the entrypoint.

I haven't used static files inside a webpack entrypoint for the moment, maybe you can open a new issue with a JSON sample ? We'll be able to implement something based on that 😄.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants