symfony / stimulus-bridge

Stimulus integration bridge for Symfony projects
https://symfony.com/ux
75 stars 15 forks source link

Activating "debug" mode for Stimulus for dev builds #65

Closed weaverryan closed 2 years ago

weaverryan commented 2 years ago

Hi!

Well... this was such an easy win, we should have done it awhile ago :).

For a "dev" build, this activates Stimulus's debug mode, which outputs a lot of information to the log. Here is an example of a page with a single controller... and then after I activate an action on that controller:

Screen Shot 2022-04-19 at 10 09 53 AM

When running yarn encore production (or npm run encore production), debug mode will be disabled. Heck, Weback is SO cool that, when building for production, the entire new if statement is omitted (i.e. this adds 0 extra bytes to production builds).

WebMamba commented 2 years ago

Hi @weaverryan thanks for this PR, small but can definitely save time for many people ! 😁 I just just think we should give access to this debug value from outside the index file. In case you have an other environment where the debug mode should be activate to. So what's you think about adding that to the bootstrap file in the recipe ? Or adding an argument to the startStimulusApp function to overwrite the debug value ?

weaverryan commented 2 years ago

Hey @WebMamba!

I'm not sure what use-case you have in mind, but I think it's not needed. You can always override this in your bootstrap.js file if you need to:


import { startStimulusApp } from '@symfony/stimulus-bridge';

// Registers Stimulus controllers from controllers.json and in the controllers/ directory
export const app = startStimulusApp(require.context(
    '@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
    true,
    /\.[jt]sx?$/
));
+ // override however you want
+ app.debug = true;

// register any custom, 3rd party controllers here
// app.register('some_controller_name', SomeImportedController);

Cheers!

WebMamba commented 2 years ago

Ha yes your right ! My bad... 😁

tgalopin commented 2 years ago

Thanks @weaverryan.