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

webpack 2 compability #7

Open
donaldpipowitch opened this issue Jul 19, 2016 · 5 comments
Open

webpack 2 compability #7

donaldpipowitch opened this issue Jul 19, 2016 · 5 comments

Comments

@donaldpipowitch
Copy link

donaldpipowitch commented Jul 19, 2016

Hi, I just checked if this plugin works with webpack 2. Currently it throws an error at index.js:46:43 for candidate.request.split('!') because candidate.request is undefined.

I try, if I can fix that.


Old candidate (webpack 1):

{ path: '/Users/foo/example/example',
  request: './src/index.tsx',
  query: null,
  directory: false }

New candidate (webpack 2):

 context: {},
  path: '/Users/foo/example/src/index.tsx',
  request: undefined,
  query: '',
  module: false,
  directory: false,
  file: false,
  descriptionFilePath: '/Users/foo/example/package.json',
  descriptionFileData:
   { /* content of package.json */ },
  descriptionFileRoot: '/Users/foo/example',
  relativePath: './src/index.tsx' }

But...

In webpack 1 I get:

  • candidate.path: /Users/foo/example/src
  • candidate.request: ./other-module/src/style.less

In webpack 2 I get:

  • candidate.path: /Users/foo/example/src/other-module/src/style.less
  • candidate.relativePath: ./src/other-module/src/style.less
@donaldpipowitch
Copy link
Author

Anyway... maybe I can stick with webpack 1 for all old projects and just don't use omit-tilde-webpack-plugin for webpack 2...

@bholloway
Copy link
Owner

That is a solution.

However it may be possible to change behaviour based on the presence of relativePath. i.e.

if ('relativePath' in candidate) {
  // webpack 2 behaviour
} else {
  // webpack 1 behaviour
}

Although I would be surprised if that is the only change to the API.

I am not in a position to try Webpack 2 right now so I would be relying on you if you wanted to progress this.

@richardaum
Copy link

+1 for Webpack 2 support!

@bholloway
Copy link
Owner

Sorry finally took a look at this.

In Webpack 1 we just added a tilde to the request and recursed. We didn't get stuck in a loop because (a) the process was synchronous (b) we only looked at requests with a leading ./.

Since Webpack 2 rationalised options.resolve it is harder to do this. During recursion you get ./node_modules/ and these overflow to ./node_modules/node_modules/node_modules....

So in short, not easy to support Webpack 2. But I will see what I can do.

@bholloway
Copy link
Owner

Take a look that this branch, works but is flaky.

There are (at minimum) race conditions with recursion detection. I'm using setTimeout() but it is not robust.

There is no one set of fields (in Webpack 2) that gives consistent information. I have been testing with sass-loader and I get different candidate to @donaldpipowitch. If anyone has a small open-source use-case project it would help to understand the request in different use-cases.

I will have to take a much deeper dive into the Webpack 2 resolver code. However I am not confident we can achieve support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants