Skip to content

Conversation

@Kocal
Copy link
Member

@Kocal Kocal commented Apr 15, 2021

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!

}

/**
* Use to conditionally configure or enable features only in when the first parameter results to "true".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Use to conditionally configure or enable features only in when the first parameter results to "true".
* Use to conditionally configure or enable features only when the first parameter results to "true".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated at sha: d074101

* // passing a callback
* .when((Encore) => Encore.isProduction(), (Encore) => Encore.enableVersioning())
* // passing a boolean
* .when(process.argv.includes('--analyze'), (Encore) => Encore.addPlugin(new BundleAnalyzerPlugin()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool examples!

@weaverryan
Copy link
Member

This is very cool - thank you @Kocal!

@weaverryan weaverryan merged commit 49ed6c8 into symfony:main Apr 22, 2021
weaverryan added a commit that referenced this pull request Apr 22, 2021
@Kocal Kocal deleted the feat/when branch April 23, 2021 06:50
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

Successfully merging this pull request may close these issues.

3 participants