webpack-contrib / imports-loader

Imports Loader
MIT License
520 stars 63 forks source link

Webpack 2? #38

Closed kentcdodds closed 7 years ago

kentcdodds commented 7 years ago

Does this loader support Webpack 2? If so, how would you specify the options with the new rules API?

For example. I have this:

{
    test: /globalize/,
    loader: 'imports?define=>false',
},

I was thinking:

{
    test: /globalize/,
    use: [{ loader: 'imports-loader', options: { 'define=>false': '' } }],
}

But I'm unsure, and it seems odd...

TheLarkInn commented 7 years ago

That actually might be something that works. It's like you mentioned the => which is the unconventional piece thats parsed here.

If you didn't have to use the `=> syntax, how would you imagine it working.

kentcdodds commented 7 years ago

Yeah, honestly, the whole thing's kinda whacky... I tried the above code and that didn't work. Not sure how to make it work properly so I'm using the old query string API for now... :-/

TheLarkInn commented 7 years ago

I mean, it looks like these symbols (first time even looking at this loader), to expand into expressions. Would it make it undesirable to just pick the type of expression needed.

kentcdodds commented 7 years ago

Yeah, honestly, I'm not a huge fan of the syntax as it is... It's pretty overloaded (just look at the table). I would rather something simpler, like:

Option value Equals
angular: 'require("angular")' var angular = require("angular");
$: 'require("jquery") var $ = require("jquery");
define: 'false' var define = false;
config: '{size:50}' var config = {size:50};
'this': 'window' (function () { ... }).call(window);

Notice that the only special case is the last one because that's kinda hard to represent in any other way... Thoughts?

djedje72 commented 7 years ago

This syntax seems to work:

loader: 'imports-loader', options: { define: ">false", module: ">false" }

ahmedelgabri commented 7 years ago

I'm using this and it still working for me:

{ 
  test: require.resolve('foo'), 
  use: ['imports-loader?this=>window', 'exports-loader?foo'] 
}
Vanuan commented 7 years ago

This is what is printed for me:

loaderUtils.parseQuery() received a non-string value which can be problematic, see https://github.com/webpack/loader-utils/issues/56
parseQuery() will be replaced with getOptions() in the next major version of loader-utils.

And it doesn't work, I still see "true" instead of typeof define == 'function'

This is the the context I'm coming from: https://github.com/webpack/webpack/issues/3017

joshwiens commented 7 years ago

@Vanuan - That is a deprecation warning from loader-utils

See: 7129a27 for exactly what was changed to accomodate the change from loader-utils

As to your specific issue, I'd need to see exactly what you are trying to do. Got a project I can go dig around in?

Vanuan commented 7 years ago

sorry, you're right, it's unrelated.

Vanuan commented 7 years ago

I've resolved my issue using a built-in option:

module: {
  rules: [
    { parser: { amd: false } }
  ]
}