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

Query to aliased resource with loader #1289

Closed
kisenka opened this Issue Jul 23, 2015 · 7 comments

Comments

Projects
None yet
7 participants
@kisenka
Copy link
Contributor

kisenka commented Jul 23, 2015

How can I pass query to aliased resource which is processed by custom loader?
Following setup doesn't work:

webpack.config.js

resolve: {
  alias: {
    'super-alias': path.join(__dirname, 'lib', 'my-module.js')
  }
},
module: {
  loaders: [
    {
      test: /my-module/,
      loader: path.resolve(__dirname, 'lib', 'loaders', 'my-custom-loader.js')
    }
  ]
}

Entry point

require('super-alias?qwe=123');

my-custom-loader

module.exports = function (content, sourceMap) {
  console.log(this.resourceQuery); // null
};

@sokra sokra added the bug label Jul 24, 2015

@jbrantly

This comment has been minimized.

Copy link

jbrantly commented Jul 28, 2015

If I'm not mistaken a similar issue exists with resolveLoader aliases.

resolveLoader: {
  alias: { 'myLoader': require('path').join(__dirname, "../../index.js") }
},
 module: {
  loaders: [
    { test: /\.js$/, loader: 'myLoader?someOption=true' }
  ]
}

this.query is blank in the loader.

But doing { test: /\.js$/, loader: '../../index.js?someOption=true' } works fine, this.query is populated correctly.

@rpora

This comment has been minimized.

Copy link

rpora commented Aug 13, 2015

Hi!

I also encounter this bug, and I found that this is related to
enhanced-resolve/ModuleAliasPlugin that does not take into account the original query to create the newRequest.

So, obj.query is inevitably null.

var obj = {
    path: request.path,
    request: newRequest.path,
    query: newRequest.query,
    directory: newRequest.directory
};

I fixed it and added a test case .

With this commit, I can do

resolveLoader: {
  alias: { 'myLoader': require('path').join(__dirname, "./my-loader.js") }
},
 module: {
  loaders: [
    { test: /\.js$/, loader: 'myLoader?someOption=true' }
  ]
}

and still access the query.

All tests are green, but I'm not sure this is the right place to fix this bug.

@sokra : Hi! What do you think about it? Should I PR or am I wrong??

@AlbertoElias

This comment has been minimized.

Copy link

AlbertoElias commented Aug 27, 2015

It would be amazing to have this fixed. Thanks @rpora for it. Hopefully you'll be given the good to go soon :)

@kisenka

This comment has been minimized.

Copy link
Contributor Author

kisenka commented Sep 2, 2015

@sokra could you kindly check @rpora's fix?

@Kreozot

This comment has been minimized.

Copy link

Kreozot commented Sep 9, 2015

@rpora, did you do pull request for this commit?

@rpora

This comment has been minimized.

Copy link

rpora commented Sep 10, 2015

Hi!
Yes, it's done! :)

usirin added a commit to koding/koding that referenced this issue Aug 9, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289

usirin added a commit to koding/koding that referenced this issue Aug 9, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289

usirin added a commit to koding/koding that referenced this issue Aug 11, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289

usirin added a commit to koding/koding that referenced this issue Aug 12, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289

usirin added a commit to koding/koding that referenced this issue Aug 16, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289

usirin added a commit to koding/koding that referenced this issue Aug 16, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289

hakankaradis added a commit to hakankaradis/koding that referenced this issue Aug 17, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289

usirin added a commit to koding/koding that referenced this issue Aug 18, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289

usirin added a commit to koding/koding that referenced this issue Aug 19, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289

usirin added a commit to koding/koding that referenced this issue Aug 23, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289

usirin added a commit to usirin/koding that referenced this issue Aug 24, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289

usirin added a commit to usirin/koding that referenced this issue Aug 24, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289

usirin added a commit to koding/koding that referenced this issue Aug 25, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289
@bebraw

This comment has been minimized.

Copy link
Member

bebraw commented Aug 29, 2016

Looks like this was resolved in webpack/enhanced-resolve#22 .

@bebraw bebraw closed this Aug 29, 2016

usirin added a commit to koding/koding that referenced this issue Aug 30, 2016

webpack: use globals-loader without alias
When using aliases it doesn't pass query parameter to loader.
Using the real path in loader config solved the issue.
see: webpack/webpack#1289
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.