-
Notifications
You must be signed in to change notification settings - Fork 3
Description
AssetMapper default exclusions break custom TinyMCE CSS in bundles
3615 MYLIFE
Today, I spent half a day trying to integrate a custom TinyMCE skin into my project, feeling like I was going crazy. I logically (?) named this skin tinymce-custom.css.
<script>
window.tinymceConfig = {
content_css: "{{ asset('@acme/assets-bundle/styles/tinymce-custom.css') }}",
}
</script>I couldn’t get it to work—everything kept failing.
The string '@acme/assets-bundle/styles/tinymce-custom.css' was never converted to real asset path...
Then... I tried in my asset mapper js file, just to test (in desperation):
import './styles/tinymce-custom.css';And I got the error
Unable to find asset "./styles/tinymce-custom.css" imported from "/app/work/packages/assets-bundle/assets/base.js" .The file "/app/work/packages/assets-bundle/assets/styles/tinymce-custom.css" exists, but it is not in a mapped asset path. Add it to the "paths" config.
So... I ran:
php bin/console debug:config framework asset_mapperAnd then… what did I see!?
Current configuration for "framework.asset_mapper"
==================================================
excluded_patterns:
- '**/**tinymce**' << WHAT!?
- '**/skins/*/appstack**'
- '*.d.ts'
- '**/controllers.json'
I looked for the guilty code in our application… nothing. Then I finally discovered it was in the bundle configuration we were using.
What is the purpose of these exclusions!?
Description
In the current version of the package, the DependencyInjection automatically prepends the following AssetMapper configuration:
if (class_exists(\Symfony\Component\AssetMapper\AssetMapper::class)) {
$container->prependExtensionConfig('framework', [
'asset_mapper' => [
'excluded_patterns' => [
'**/**tinymce**',
'**/skins/*/appstack**',
],
],
]);
}This causes any CSS files containing tinymce in their path, including custom TinyMCE builds in the main project, or private bundles (e.g. tinymce-custom.css), to be ignored by AssetMapper. This breaks the ability to import and fingerprint custom TinyMCE CSS files.
Steps to reproduce
As simple asset
- Create a custom TinyMCE CSS file in a private bundle:
assets/styles/tinymce-custom.css
- Import it in a JS file or link it in a Twig template using AssetMapper:
{{ asset('@acme/assets-bundle/styles/tinymce-custom.css') }}- The asset stays in 404.
Expected behavior
- Only the original TinyMCE vendor skins (
skins/*/appstack) should be excluded. - Custom CSS in the bundle should be included normally and fingerprinted.
Proposed solution
- Do not prepend
excluded_patternsautomatically in the bundle’s DependencyInjection. - If exclusion is needed, it should be optional or configurable by the user.
- At minimum, avoid a blanket
**/**tinymce**exclusion that blocks all custom TinyMCE CSS. - Or add the bundle name in the ignored path!
Environment
- Symfony 6.4+
- AssetMapper enabled
- Private bundle with custom TinyMCE CSS