-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Webpack 2 support #265
Comments
Need a Webpack 2.0 resolver. Could be a new package ( |
FYI, here's the readme section on resolvers: https://github.com/benmosher/eslint-plugin-import#resolvers The I'm not planning to implement this any time soon, but a PR with a |
Actually, now that I've read through that section again, I can imagine supporting both at once in the Webpack resolver. Would be worth a shot, anyway, might be simpler than forking or trying to share common code. |
Thanks for the updates. I beg to defer on your opinion on the adoption of webpack 2. I think webpack 2 will be adopted soon rather than never. Yes the config is a pain but the native support for es6 modules will be worth it. Looking at the config for webpack 2 and what you have for {
resolve: {
extensions: ['', '.jsx', '.scss', '.js', '.json', '.styl', 'ts', 'tsx'],
modules: [
'web_modules',
'node_modules',
'shared',
'res'
]
},
} The
In my case revenue can import something like |
Just to clarify: I assume the community will adopt it pretty immediately, but I don't expect to use it at my day job for a while, if for no other reason than that v1 is working fine. 😄 So I just want to make sure that whatever happens, Webpack v1 support is preserved, that's all. I think what you've described could be pretty easily supported with some tweaks in place to the existing Webpack resolver, without compromising v1 support. |
Just a note: want to use this with the Webpack 2 resolver: https://github.com/webpack/enhanced-resolve/blob/master/lib/ResolverFactory.js#L38 Will also need to refactor the path sanitizing (removing loaders and queries) and config-finding into some shared module. Still pretty sure we'll need 2 modules, as the Webpack 2 version will need to find/depend on (and I don't think we can assume the live |
btw, according to my tests you can use the webpack1 syntax in your webpack.config.js alongside webpack2 syntax. This way both import eslinter and webpack2 work: {
//...
resolve: {
modules: [path.resolve('./src'), 'node_modules'],
root: path.resolve('./src')
}
} |
Would you accept a PR that makes the package resolution lenient in a hack-ish way that pragmatically gives effective webpack 2 compatibility? For example, at https://github.com/benmosher/eslint-plugin-import/blob/resolvers/webpack/v0.4.0/resolvers/webpack/index.js#L138, we could do: resolve.modulesDirectories || resolve.modules || ['web_modules', 'node_modules'] This wouldn't be correct "per se", but it would work. |
You need to filter by relative / absolute paths. |
@taion would be dependent on the PR details, but I'm not generally opposed. That said, I'm not sure that making a "real" Webpack 2 resolver is a long walk away, and I would prefer that. |
I agree that it's not. It'd be a way to not have to have an |
Another way would be to resolve Then could branch inside the resolver based on the version in Would be a little bit better, potentially, as it would guarantee that the same exact version of |
The problem is that |
|
I was imagining using stock A bit convoluted? Sure. But assuming it's >90% correct, it'd be incredibly convenient. Biggest leap is finding the right |
@Kovensky's solution would also probably work a lot of the time. |
Added in #475, using |
Anyone know how to install the resolver from a fork? Just installing the fork doesn't seem to work... |
I think you have to clone it and install from the local path. |
git clone https://github.com/taion/eslint-plugin-import.git
cd eslint-plugin-import
git checkout webpack-2
cd resolvers/webpack
npm install
pwd ^^^ take the folder output by that final pwd command and put it in your eslintrc settings. "extends": "airbnb",
"root": true,
"settings": {
"import/resolver": {
"/home/me/eslint-plugin-import/resolvers/webpack": {}
}
} You can use the I'm using @taion can you try adding some code to check if the config is a function right before line 82 of index.js? Probably need to add a unit test for that use case too. // webpack 2 config function support
if (typeof webpackConfig === 'function') {
var configOptions = get(settings, 'config-options') || {}
webpackConfig = webpackConfig(configOptions)
} Once I add the above block, it works for my usage of eslint with webpack 2. I took a stab at implementing it too, but I didn't know about recent webpack 1's usage of enhanced-resolve. I thought a separate webpack-2 resolver was going to be necessary. Awesome. Thanks!! |
Wait, what? Does webpack 2 support functions for configs? I've not seen that feature – any details? |
@taion Yup. It's mentioned here: https://gist.github.com/sokra/27b24881210b56bbaff7#configuration and here: https://webpack.github.io/docs/roadmap.html |
I feel like that might make more sense as a separate PR. Among other things, it'd require additional docs, rather than just "things will now just work for similar webpack 2 configs". |
Sure. I could potentially take on that PR after #475 is merged. |
You'd also need a separate option to specify which |
My snippet above supports a "config-options" setting in the import/resolver eslint settings and passes that to the function. I think that's a decent solution for most uses. |
@rmarscher, FYI: just published v0.6.0 of the resolver, it includes support for webpack-config-as-function 😎 via #533 |
@benmosher That's great. Thanks for remembering to ping me. People might open issues about needing to pass an argument to that webpack function which is what happens in the command-line version when you use the
As @Kovensky pointed out, there are going to be a lot of different ways the function will need to be called for different use cases, so maybe recommending this approach keeps from having to handle all of that within this plugin. |
Resolve options in webpack 2.0 is considerably changed. Any way to support that now?
The text was updated successfully, but these errors were encountered: