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

feat: add Encore.when() #963

Merged
merged 1 commit into from
Apr 22, 2021
Merged

feat: add Encore.when() #963

merged 1 commit into from
Apr 22, 2021

Conversation

Kocal
Copy link
Contributor

@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!

index.js Outdated Show resolved Hide resolved
@@ -1596,6 +1596,29 @@ class Encore {
return webpackConfig.isDevServer();
}

/**
* 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.

None yet

3 participants