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

[Fix for Webpack 2 Beta 24+] Get loader options from query instead of raw this.options #361

Merged

Conversation

JoshTheDerf
Copy link

@JoshTheDerf JoshTheDerf commented Sep 25, 2016

The current way to handle Webpack 2 Beta 24+ involves the use of LoaderOptionsPlugin. This is non-ideal, as LoaderOptionsPlugin actually mangles this.options in loaders to refer to its configuration instead of what webpack normally passes. Because of this, LoaderOptionsPlugin should be used only as a stopgap until a fix is introduced to make the loader compatible with Webpack 2 Beta 24+ by loading its options from this.query instead of this.options.x.

Current Usage (LoaderOptionsPlugin):

module.exports = {
  ...
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue'
      },
      ...
    ]
  },
  plugins: [
    new webpack.LoaderOptionsPlugin({
      vue: {
        ...
      }
    })
  ]
}

Recommended Usage (Works after this patch) (Current and Webpack 1.x usages still work and can mix & match):

module.exports = {
  ...
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue',
        options: { // query works as well here.
          vue: {
            ...
          }
        }
      },
      ...
    ]
  }
}

I hope this is of use. The removal of references to this.options may cause breakages in Webpack 1.x, though all tests are passing. If someone wants to confirm this, feel free.

…an be passed an object and this.options is mounted to this.query
var query = loaderUtils.parseQuery(this.query)
var options = this.options.vue || query || {}
Copy link
Member

Choose a reason for hiding this comment

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

I think we should

  1. keep this.vue for current usage compatibility
  2. prioritize query first

So perhaps query || this.vue || this.options.vue || {}

Copy link
Author

@JoshTheDerf JoshTheDerf Oct 11, 2016

Choose a reason for hiding this comment

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

Alright, will do. I believe there was a reason I couldn't keep query at the front, I'll check

Copy link
Author

@JoshTheDerf JoshTheDerf Oct 11, 2016

Choose a reason for hiding this comment

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

@yyx990803 Alright, so the issue is that query is an empty object by default, and therefore needs to be at the end of the list.
Perhaps we should try merging this.options.vue and this.vue into query?

As of the new commit, it tests the this.query string for emptiness, in which case it skips over query to this.vue and so on. I'm not a huge fan of this as it seems hackish, but it should work for now.
Ideally query and options would be combined into the same object, as in Webpack 2. Any thoughts on this?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, merging makes sense. So something like Object.assign({}, this.options.vue, this.vue, query) should suffice.

Copy link
Member

Choose a reason for hiding this comment

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

I'll merge it now and tweak - thanks for the effort!

Copy link
Author

Choose a reason for hiding this comment

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

No problem! Thanks for the merge! Great work on Vue. :)

@yyx990803 yyx990803 merged commit ce32a5c into vuejs:next Oct 11, 2016
yyx990803 pushed a commit that referenced this pull request Oct 11, 2016
… raw this.options (#361)

* Get options from query instead of this.options. In Webpack 2, query can be passed an object and this.options is mounted to this.query

* Prioritize Query, re-add this.vue
hinablue pushed a commit to hinablue/vue-loader that referenced this pull request Oct 26, 2016
… raw this.options (vuejs#361)

* Get options from query instead of this.options. In Webpack 2, query can be passed an object and this.options is mounted to this.query

* Prioritize Query, re-add this.vue
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.

2 participants