Skip to content

fix: contextify sourceMap #533

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

Closed
wants to merge 4 commits into from

Conversation

helloyou2012
Copy link

@helloyou2012 helloyou2012 commented May 28, 2020

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

some loader (like postcss-loader) generate the source map with the absolute path. Cause contentHash differences on different project paths.

Breaking Changes

Additional Info

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

We should not contextify source map, it should be done on css-loader side, webpack need to absolute sources

@helloyou2012
Copy link
Author

#512

@helloyou2012
Copy link
Author

helloyou2012 commented May 29, 2020

@evilebottnawi I don't think it should be done on css-loader side. Even if do it on css-loader side, it does not guarantee the other loaders contextify. So I think it should do on this plugin. Webpack is also contextify source map first and don't need to absolute sources.

@alexander-akait
Copy link
Member

No, we need absolute sources for webpack, you break source maps, other CSS files on a page can have source maps too with relative sources (for example src/style.css)

some loader (like postcss-loader) generate the source map with the absolute path.

postcss-loader doesn't create source maps with absolute paths

@alexander-akait
Copy link
Member

@helloyou2012 It is a bug in postcss-loader, using path.resolve is a wrong idea, without absolute sources webpack will be generate broken source maps

@helloyou2012
Copy link
Author

path.resolve return absoluted paths.

@alexander-akait
Copy link
Member

@helloyou2012 yep, but they may not necessarily be relatively to current process cwd

@helloyou2012
Copy link
Author

So postcss-loader should keep the original relative path and no need resolve it?

@alexander-akait
Copy link
Member

@helloyou2012 postcss-loader should generate right sources with absolute paths, css-loader should contextify using webpack://, webpack automatically absolute them https://github.com/webpack/webpack/blob/master/lib/SourceMapDevToolPlugin.js#L78

@helloyou2012
Copy link
Author

why not contextify using webapck:// on this plugin?

@alexander-akait
Copy link
Member

@helloyou2012 because this plugins should not do it

@alexander-akait
Copy link
Member

@helloyou2012 and we still have the same problem with style-loader, so it is better to fix it on css-loader side

@helloyou2012
Copy link
Author

Is this pr to fix this bug?
webpack-contrib/css-loader#1031

@alexander-akait
Copy link
Member

@helloyou2012 yep, bug we need a new a PR, contextify is better solution

@codecov
Copy link

codecov bot commented Jul 8, 2020

Codecov Report

Merging #533 into master will decrease coverage by 1.16%.
The diff coverage is 57.89%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #533      +/-   ##
==========================================
- Coverage   88.55%   87.38%   -1.17%     
==========================================
  Files           5        5              
  Lines         428      444      +16     
  Branches       96      105       +9     
==========================================
+ Hits          379      388       +9     
- Misses         47       51       +4     
- Partials        2        5       +3     
Impacted Files Coverage Δ
src/index.js 85.65% <57.89%> (-2.20%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25b0ecd...b55b2ad. Read the comment docs.

@alexander-akait
Copy link
Member

Fixed on css-loader side (now we always pass webpack://./rootDirectory/my-style.css sources), fix for postcss-loader will be in near future

@alexander-akait
Copy link
Member

alexander-akait commented Aug 26, 2020

Just update css-loader to latest version 4.2.2

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