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

implement mix.when() #2330

Merged
merged 1 commit into from Apr 2, 2020
Merged

implement mix.when() #2330

merged 1 commit into from Apr 2, 2020

Conversation

claytonrcarter
Copy link
Contributor

Hi, this adds a small DX/QOL improvement: mix.when(). Mix has a wonderful, fluent API, and it often feels a little janky to me to break out of that when needing to do some conditional configuration. I hope that this helper will reduce that a little bit. This is of course inspired by Laravel's various ->when($condition, $callback) helpers.

I added mix.when() to the stock webpack.config.js, but I wasn't sure if/where to add it to docs. If you could suggest the right place to add some docs, I'd be happy to do so. Oh, and this also includes a very minor docblock fix in Api.js.

Example

From one of my own webpack.config.js:

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')

if (process.env.NODE_ENV !== 'bundle') {
    mix.extract(['vue', 'vuex', 'axios'])
}

if (mix.inProduction()) {
    mix.version()
}

Which this PR, this could be rewritten as:

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .when(
        process.env.NODE_ENV !== 'bundle',
        mix => mix.extract(['vue', 'vuex', 'axios'])
    )
    .when(
        mix.inProduction(),
        mix => mix.version()
    )

Thanks!

@JeffreyWay
Copy link
Collaborator

Nice - thanks!

@JeffreyWay JeffreyWay merged commit d1b4fc7 into laravel-mix:master Apr 2, 2020
@claytonrcarter claytonrcarter mentioned this pull request Mar 4, 2021
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

2 participants