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

Support cascading options #21

Closed
jamesplease opened this issue Apr 28, 2014 · 2 comments
Closed

Support cascading options #21

jamesplease opened this issue Apr 28, 2014 · 2 comments

Comments

@jamesplease
Copy link

Most grunt multitasks support cascading options. grunt-webpack doesn't seem to.

// This should work, but it does not
grunt.initConfig({
  webpack: {
    dev: {
      options: webpackDevOptions
    },
    prod: {
      options: webpackProdOptions
    }
  }
});

This is possibly due to this unusual pattern.

The general practice to get the options is through the this.options method, which allows you to merge defaults. Here's an example.

I'm willing to make up a PR to fix this @sokra, if it's something you're willing to support / if you think it's possible (to be honest I'm not too sure what getWithPlugins is doing).

Update...

Yup, you ignore the target options by going straight to grunt.config over here.

Update2...

This may be as simple as doing this:

var options = this.options(_.merge(
            {
                context: ".",
                output: {
                    path: "."
                },
                failOnError: true
            },
            getWithPlugins([this.name, "options"]),
            getWithPlugins([this.name, this.target]),
            function(a, b) {
                return grunt.util._.isArray(a) && grunt.util._.isArray(b) ? a.concat(b) : undefined;
            }
        ));

This seems to be working for me for now, but more testing is needed.

@sokra
Copy link
Member

sokra commented Apr 28, 2014

Do it this way:

grunt.initConfig({
  webpack: {
    options: webpackCommonOptions,
    dev: webpackDevOptions,
    prod: webpackProdOptions
  }
});

See example here and documentation here.

this.options doesn't work because it clones the object which only works with objects. It would convert webpack plugins to objects (prototype is lost).

@jamesplease
Copy link
Author

Gotcha @sokra. Thanks!

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

No branches or pull requests

2 participants