Skip to content
This repository was archived by the owner on Aug 27, 2026. It is now read-only.

fix: contextify sourceMap - #533

Closed
helloyou2012 wants to merge 4 commits into
webpack:masterfrom
helloyou2012:master
Closed

helloyou2012 wants to merge 4 commits into
webpack:masterfrom
helloyou2012:master

Conversation

@helloyou2012

@helloyou2012 helloyou2012 commented May 28, 2020 •

Copy link
Copy Markdown

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

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Author

#512

@helloyou2012

Copy link
Copy Markdown
Author

@helloyou2012

helloyou2012 commented May 29, 2020 •

Copy link
Copy Markdown
Author

@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
Copy Markdown
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

@helloyou2012

Copy link
Copy Markdown
Author

@alexander-akait

Copy link
Copy Markdown
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
Copy Markdown
Author

path.resolve return absoluted paths.

@alexander-akait

Copy link
Copy Markdown
Member

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

@helloyou2012

Copy link
Copy Markdown
Author

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

@alexander-akait

Copy link
Copy Markdown
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
Copy Markdown
Author

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

@alexander-akait

Copy link
Copy Markdown
Member

@helloyou2012 because this plugins should not do it

@alexander-akait

Copy link
Copy Markdown
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
Copy Markdown
Author

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

@alexander-akait

Copy link
Copy Markdown
Member

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

@codecov

codecov Bot commented Jul 8, 2020 •

Copy link
Copy Markdown

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
Copy Markdown
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

alexander-akait commented Aug 26, 2020 •

Copy link
Copy Markdown
Member

Just update css-loader to latest version 4.2.2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants