Skip to content

Conversation

alexhisen
Copy link

@alexhisen alexhisen commented Mar 18, 2020

This PR contains a:

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

Motivation / Use-Case

When css-loader calls postcss with an existing source map previously generated by postcss-loader, the resulting source map ends up with just the file name for sources without any paths. If there are then collisions of this file name with other same-named files in other directories, only one of these source maps ends up being retained.

This is particularly noticeable for the react-toolbox project which has about a dozen files all named theme.modules.css in different directories.

See https://github.com/alexhisen/mobx-forms-demo project for example config, etc. Note it's currently set up to use this fork, so it doesn't exhibit the problem any more.

Additional Info

This fix is a dirty hack workaround. There is probably a better way to fix this issue but I don't know enough about webpack, postcss, or this loader to know how to fix this better.

 source files in existing map previously generated by postcss-loader
@jsf-clabot
Copy link

jsf-clabot commented Mar 18, 2020

CLA assistant check
All committers have signed the CLA.

 source files in existing map previously generated by postcss-loader
// files in existing map previously generated by postcss-loader:
if (result.map && map && map.file) {
/* eslint-disable no-underscore-dangle, no-param-reassign */
result.map._sourceRoot = path.dirname(map.file);
Copy link
Member

Choose a reason for hiding this comment

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

Ideally sourceRoot should be empty and each sources relative to webpack context with unique prefix, we will improve source maps for css pipeline in near future, so please open issue with reproducible test repo and we will find solution

@alexander-akait
Copy link
Member

Sorry for delay, let's close this in favor #1169, we improve source map supporting, the next version will fix most of bugs

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.

3 participants