7.5 Admin: Assets Migration
When to Execute
This step is OPTIONAL. Execute only if your plugin has custom JavaScript or CSS in admin panel.
Overview
Sylius 2.0 requires all assets to be in the assets/ directory:
Target structure:
Admin:
assets/admin/Shop:
assets/shop/Compiled by Webpack Encore
Imported in entrypoint files
Your assets might currently be in:
src/Resources/public/(old Sylius 1.x location)assets/(already in correct location, but may need updates)Inline in templates (should be extracted)
Goal: Move everything to assets/admin/ or assets/shop/ and use modern approaches (Live Components, Stimulus, or imports)
π― Decision Guide
β
Option 1: Rewrite to Live Component (RECOMMENDED if you know how)
Use when: You know Live Components and can rewrite JavaScript logic to PHP
Example: Auto-generate slug from name
Benefits:
No JavaScript needed
Server-side logic
Type safety
Testable
Learn more:
Admin Templates - Custom Live Component
β
Option 2: Rewrite to Stimulus Controller (RECOMMENDED if you know how)
Use when: You know Stimulus and can rewrite JavaScript to Stimulus controller
Good for: Modals, dropdowns, tabs, tooltips, interactive UI
Note: Sylius already includes Stimulus - no additional installation needed.
1. Create Stimulus controller
assets/admin/controllers/modal_controller.js:
2. Register controller
assets/admin/controllers.json:
3. Use in templates
Learn more: Sylius - Customizing Dynamic Elements
Option 3: Move to assets/admin/ + Import in Entrypoint
Use when: You want to migrate existing JavaScript without rewriting
1. Move JavaScript file to assets/admin/
2. Import in entrypoint
assets/admin/entrypoint.js:
3. Rebuild assets
CSS/SCSS Migration
1. Move CSS to assets/admin/
2. Import in entrypoint
assets/admin/entrypoint.js:
3. Use Bootstrap 5 variables
4. Rebuild assets
Declaring External JavaScript Dependencies
Important: If your JavaScript imports external packages (not starting with . or @symfony), you must declare them in tests/TestApplication/package.json.
Example: If using Swiper, Chart.js, Flatpickr, etc.:
tests/TestApplication/package.json:
Note: End users will need to install these packages in their applications. Document this in UPGRADE.md or README.md.
Validation
After migration, verify:
Last updated
Was this helpful?
