-
-
Notifications
You must be signed in to change notification settings - Fork 201
Adding ifProd() and ifDev() methods #900
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
Adding ifProd() and ifDev() methods #900
Conversation
Nice idea! What about |
I thought about that... and this does introduce some inconsistency. The new method |
Hum alright, I see your point! |
Also, I've been thinking about this for a long time but, WDYT about a more generic method like Encore
.when(true, Encore => Encore.foo())
.when(() => true, Encore => Encore.bar())
.when(Encore => Encore.isDev(), Encore => Encore.baz()) A usecase I have on many projects at work is to add // Before
// ...
if (process.argv.includes('--analyze')) {
Encore.addPlugin(new BundleAnalyzerPlugin({ analyzerHost: '0.0.0.0' }));
}
// After
Encore
// ...
.when(process.argv.includes('--analyze'), Encore => Encore.addPlugin(new BundleAnalyzerPlugin({ analyzerHost: '0.0.0.0' })); |
I really like that idea. |
…s to vary by env (nicolas-grekas) This PR was merged into the 5.3-dev branch. Discussion ---------- [FrameworkBundle] allow container/routing configurators to vary by env | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #40215 | License | MIT | Doc PR | - Inspired by symfony/webpack-encore#900 and by a chat on Slack with @weaverryan This aims at allowing conditional configuration, which would allow merging config files in one. Using the PHP-DSL: ```php $container ->when(env: 'prod') ->services() ->set(Foo::class) //... ``` In Yaml: ```yaml framework: secret: '%env(APP_SECRET)%' when@dev: services: App\FooForDev: ~ when@test: framework: test: true session: storage_factory_id: session.storage.mock_file ``` In XML (omitting namespaces): ```xml <when env="test"> <framework test="true"> <!-- ... --> </framework> </when> ``` A similar syntax is also provided for routes, with support for annotations: `@Route(env="prod")` defines a route that is enabled only on the "prod" env. Commits ------- 108375b [FrameworkBundle] allow container/routing configurators to vary by env
…s to vary by env (nicolas-grekas) This PR was merged into the 5.3-dev branch. Discussion ---------- [FrameworkBundle] allow container/routing configurators to vary by env | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #40215 | License | MIT | Doc PR | - Inspired by symfony/webpack-encore#900 and by a chat on Slack with @weaverryan This aims at allowing conditional configuration, which would allow merging config files in one. Using the PHP-DSL: ```php $container ->when(env: 'prod') ->services() ->set(Foo::class) //... ``` In Yaml: ```yaml framework: secret: '%env(APP_SECRET)%' when@dev: services: App\FooForDev: ~ when@test: framework: test: true session: storage_factory_id: session.storage.mock_file ``` In XML (omitting namespaces): ```xml <when env="test"> <framework test="true"> <!-- ... --> </framework> </when> ``` A similar syntax is also provided for routes, with support for annotations: `@Route(env="prod")` defines a route that is enabled only on the "prod" env. Commits ------- 108375b068 [FrameworkBundle] allow container/routing configurators to vary by env
Replace symfony#900 by adding a more generic and flexible API than Encore.isDev()/Encore.isProd(). Encore.when() takes two parameters: - `condition`: can be a callback (where the current instance of Encore is passed as first parameter) or a boolean. If this results to `true, the parameter `callback` is called - `callback`: executed when parameter `condition` results to `true`, it takes the current instance of Encore as first parameter
This PR was squashed before being merged into the main branch. Discussion ---------- feat: add Encore.when() Replace #900 by adding a more generic and flexible API than `Encore.isDev()`/`Encore.isProd()`, see #900 (comment). `Encore.when()` takes two parameters: - `condition`: can be a callback (where the current instance of Encore is passed as first parameter) or a boolean. If this results to `true`, the parameter `callback` is called - `callback`: executed when parameter `condition` results to `true`, it takes the current instance of Encore as first parameter WDYT? Thanks! Commits ------- 8082c61 feat: add Encore.when()
Hi!
This occurred to me when I was trying to add
Encore.enableBuildCache()
to the official recipe. I was thinking that it might be best to enable it except when doing a production build. Currently, that's only possible by breaking the chaining:We have always handled making this easier on a method-by-method basis, which is still probably nice in many cases (e.g. .
.enableVersioning(Encore.isProduction())
reads really nice. But these new methods make it possible to keep chaining with anything else we don't support in this way:Cheers!