@@ -205,3 +205,111 @@ to the container::
205
205
return is_file($bundlesMetadata['FrameworkBundle']['path'] . '/Resources/config/asset_mapper.php');
206
206
}
207
207
}
208
+
209
+ Expose an entrypoint
210
+ --------------------
211
+
212
+ An entrypoint is a file that need to be always loaded, to usually start your application.
213
+
214
+ It's usefull if your bundle have dedicated views, for example :
215
+
216
+ * /admin
217
+ * /translations
218
+ * /dashboard
219
+
220
+
221
+ On a Standard symfony app, it's the ``app `` loaded by webpack encore or importmap.
222
+
223
+ With Webpack Encore
224
+ ~~~~~~~~~~~~~~~~~~~
225
+
226
+ In the ``package.json `` file, define your entrypoint inside the ``symfony.entrypoints `` key:
227
+
228
+ .. code-block :: json
229
+
230
+ {
231
+ "name" : " @acme/feature" ,
232
+ "symfony" : {
233
+ "entrypoints" : {
234
+ "@acme/feature/entrypoint" : " ../node_modules/@acme/feature/entrypoint.js"
235
+ }
236
+ }
237
+ }
238
+
239
+
240
+ The key is the entry that will be called in your templates, and the value is the path that webpack will use to load the file.
241
+
242
+ .. note ::
243
+
244
+ The path must be relative to ``assets `` folder of the symfony application.
245
+
246
+
247
+ That value will be copied inside the ``assets/controllers.json `` file after the bundle installation.
248
+
249
+ In your templates, make sure to load that entry :
250
+
251
+ .. code-block :: html+twig
252
+
253
+ {# templates/my-bundle-base.html.twig #}
254
+ ...
255
+ {% block stylesheets %}
256
+ {{ encore_entry_link_tags('@acme/feature/entrypoint') }}
257
+ {% endblock %}
258
+
259
+ {% block javascripts %}
260
+ {{ encore_entry_script_tags('@acme/feature/entrypoint') }}
261
+ {% endblock %}
262
+
263
+
264
+ .. warning ::
265
+
266
+ Is it mandatory to have stimulus-bundle and the ``.enableStimulusBridge('./assets/controllers.json') `` added to the webpack.config.js to be able to use the entrypoints.
267
+
268
+
269
+ With Asset Mapper
270
+ ~~~~~~~~~~~~~~~~~
271
+
272
+ In the ``package.json `` file, define your entrypoint inside the ``symfony.importmap `` key:
273
+
274
+ .. code-block :: json
275
+
276
+ {
277
+ "name" : " @acme/feature" ,
278
+ "symfony" : {
279
+ "importmap" : {
280
+ "@acme/feature/entrypoint" : " entrypoint:%PACKAGE%/entrypoint.js"
281
+ }
282
+ }
283
+ }
284
+
285
+ .. versionadded :: 2.7.0
286
+
287
+ The ``entrypoint `` keyword support was introduced in Symfony Flex 2.7.0
288
+
289
+
290
+ After installation, the entry will be added to the ``importmap.php ``:
291
+
292
+ .. code-block :: php
293
+
294
+ // importmap.php
295
+ return [
296
+ 'app' => [
297
+ 'path' => './assets/app.js',
298
+ 'entrypoint' => true,
299
+ ],
300
+ // ...
301
+ '@acme/feature/entrypoint' => [
302
+ 'path' => './vendor/acme/feature-bundle/assets/entrypoint.js',
303
+ 'entrypoint' => true,
304
+ ],
305
+ ];
306
+
307
+ In your templates, make sure to load that entry :
308
+
309
+ .. code-block :: html+twig
310
+
311
+ {# templates/my-bundle-base.html.twig #}
312
+ ...
313
+ {% block javascripts %}
314
+ {% block importmap %}{{ importmap('@acme/feature/entrypoint') }}{% endblock %}
315
+ {% endblock %}
0 commit comments