Closed KIMKYEONGYONG closed 11 months ago
I'm not sure :). Each file should only run 1 time. Perhaps you can throw an error in the file to see where each "call" is coming from.
html v1)
{% block javascripts %}
{{ encore_entry_script_tags('media')}}
{% endblock %}
console result
test media ( 1 call)
html v2)
{% block javascripts %}
{{ parent() }}
{% endblock %}
console result
test app ( 1 call)
html v3)
{% block javascripts %}
{{ parent() }}
{{ encore_entry_script_tags('media')}}
{% endblock %}
console result
app.js:29 test app.
media.js:4 test media
app.js:29 test app
media.js:4 test media
why call console 2 time???
The cause I think is this: TagRenderer entrypointLookupCollection
(yaml.xml) 2 call yaml.xml
'webpack_encore.entrypoint_lookup_collection' => static function(): EntrypointLookupCollectionInterface {
$serviceLocator = new ServiceLocator(['_default' => function() {
return new EntrypointLookup(DIST_PATH . '/entrypoints.json');
}]);
return new EntrypointLookupCollection($serviceLocator);
},
'webpack_encore.packages' => static fn(): Packages => new Packages(
new Package(new JsonManifestVersionStrategy(DIST_PATH . '/manifest.json'))
),
'webpack_encore.tag_renderer' => static fn(ContainerInterface $container): TagRenderer => new TagRenderer(
$container->get('webpack_encore.entrypoint_lookup_collection'),
$container->get('webpack_encore.packages')
),
1 call yaml.xml
'webpack_encore.packages' => static fn() => new Packages(
new Package(new JsonManifestVersionStrategy(DIST_PATH . '/manifest.json'))
),
'webpack_encore.tag_renderer' => static fn(ContainerInterface $container) => new TagRenderer(
new EntrypointLookup(DIST_PATH . '/entrypoints.json'),
$container->get('webpack_encore.packages')
),
but 1 call yaml.xml is trigger_error !!
before my code << encore_entry_script_tags * count is call ( new Instance )
'webpack_encore.entrypoint_lookup_collection' => static function(): EntrypointLookupCollectionInterface {
$serviceLocator = new ServiceLocator(['_default' => function() {
return new EntrypointLookup(DIST_PATH . '/entrypoints.json');
}]);
return new EntrypointLookupCollection($serviceLocator);
},
after my code
'webpack_encore.entrypoint_lookup_collection' => static function(): EntrypointLookupCollectionInterface {
$entrypointLookup = new EntrypointLookup(DIST_PATH . '/entrypoints.json');
$serviceLocator = new ServiceLocator(['_default' => function () use ($entrypointLookup) {
return $entrypointLookup;
}]);
return new EntrypointLookupCollection($serviceLocator);
},
my webpack.js
html
media.js
app.js
container_bindings.php ( => yaml.xml)
conosle reuslt test app 2 test media 2
why js is 2 time run??