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

Updating stimulus-bundle and other ux recipes with constraint from third party package #1335

Open
lhapaipai opened this issue Aug 22, 2024 · 0 comments

Comments

@lhapaipai
Copy link

lhapaipai commented Aug 22, 2024

Hello Symfony Team and thanks for all your work, it's amazing !

I noticed that stimulus-bundle recipe adds lines in assets/bootstrap.js file and these differ depending on Composer dependencies.

{
    "bundles": {
        "Symfony\\UX\\StimulusBundle\\StimulusBundle": ["all"]
    },
    "add-lines": [
        {
            "file": "assets/bootstrap.js",
            "content": "import { startStimulusApp } from '@symfony/stimulus-bridge';\n\n// Registers Stimulus controllers from controllers.json and in the controllers/ directory\nexport const app = startStimulusApp(require.context(\n    '@symfony/stimulus-bridge/lazy-controller-loader!./controllers',\n    true,\n    /\\.[jt]sx?$/\n));",
            "position": "top",
            "requires": "symfony/webpack-encore-bundle"
        },
        {
            "file": "assets/bootstrap.js",
            "content": "import { startStimulusApp } from '@symfony/stimulus-bundle';\n\nconst app = startStimulusApp();",
            "position": "top",
            "requires": "symfony/asset-mapper"
        },        
    ]
}

I was wondering if it was possible to update the recipe to add content but this time the dependency would not be from the symfony/* namespace but pentatrion/vite-bundle ?

I am the maintainer of this bundle that allows to integrate Vite into a Symfony application. Vite natively uses ESM, the @symfony/stimulus-bridge package is only compatible with commonjs and cannot be used. (it uses require.context)

the project documentation is here: https://symfony-vite.pentatrion.com

as an example I would like the symfony/stimulus-bundle recipe to make changes to the bootstrap.js file to make it look like this.

// assets/bootstrap.js
import { startStimulusApp, registerControllers } from "vite-plugin-symfony/stimulus/helpers";

const app = startStimulusApp();
registerControllers(
  app,
  import.meta.glob('./controllers/*_controller.js', {
    query: "?stimulus",
    /**
     * always true, the `lazy` behavior is managed internally with
     * import.meta.stimulusFetch
     */
    eager: true,
  })
)

It's been about 1 year since I made Vite compatible with the stimulus-bundle ecosystem and Symfony UX and the integration is now stable.

Currently the whole thing works but it requires additional work from the developer. In order to improve the developer experience I would like to intervene on certain recipes.

So I would like to know if a PR from me could be accepted?

My request concerns

and the github: https://github.com/lhapaipai/symfony-vite-dev

Thank you and have a good evening

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

1 participant