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

postcss-loader changes the relative path of url() function returned from sass-loader #500

Closed
tianzhich opened this issue Nov 20, 2020 · 7 comments

Comments

@tianzhich
Copy link

tianzhich commented Nov 20, 2020

  • Operating System: MacOS 10.15.4
  • Node Version: v14.5.0
  • NPM Version: 6.14.5
  • webpack Version: 4.42.0
  • postcss-loader Version: 3.0.0

Expected Behavior

I don't want postcss-loader to change the relative path in url(), so it can be resolved by the next css-loader. Is there an option I can use to disable it?

Actual Behavior

The path changed from ../assets/foo.png to ./foo.[hash:20].png. And the file generated in the root of the dist folder.

Code

// webpack.config.js
{
  "exclude": [
    "/Users/tianzhi/dev/nx-examples/libs/shared/styles/src/index.scss",
    "/Users/tianzhi/dev/nx-examples/libs/shared/header/index.scss",
    "/Users/tianzhi/dev/nx-examples/node_modules/normalize.css/normalize.css"
  ],
  "test": "/\\.scss$|\\.sass$/",
  "use": [
    {
      "loader": "/Users/tianzhi/dev/nx-examples/node_modules/@nrwl/web/node_modules/style-loader/dist/index.js"
    },
    {
      "loader": "/Users/tianzhi/dev/nx-examples/node_modules/@nrwl/web/node_modules/css-loader/dist/cjs.js"
    },
    {
      "loader": "/Users/tianzhi/dev/nx-examples/node_modules/postcss-loader/src/index.js",
      "options": { "ident": "embedded", "sourceMap": false }
    },
    {
      "loader": "/Users/tianzhi/dev/nx-examples/node_modules/@nrwl/web/node_modules/sass-loader/dist/cjs.js",
      "options": {
        "implementation": {
          "info": "dart-sass\t1.26.10\t(Sass Compiler)\t[Dart]\ndart2js\t2.8.4\t(Dart Compiler)\t[Dart]",
          "types": {},
          "NULL": {},
          "TRUE": { "value": true },
          "FALSE": { "value": false }
        },
        "sourceMap": false,
        "sassOptions": { "precision": 8, "includePaths": [] }
      }
    }
  ]
},
@alexander-akait
Copy link
Member

alexander-akait commented Nov 20, 2020

postcss-loader doesn't touch your url, double check your plugins

@alexander-akait
Copy link
Member

alexander-akait commented Nov 20, 2020

Every time when we ask to create reproducible test repo, developers ignore us, but if you look at closed PR by me, you can found around 99% issues resolved by developers when they try to create reproducible test repo, they found problems in own environments and fix it

@tianzhich
Copy link
Author

Every time when we ask to create reproducible test repo, developers ignore us, but if you look at closed PR by me, you can found around 99% issues resolved by developers when they try to create reproducible test repo, they found problems in own environments and fix it

Thank you a lot, I used 3rd party tools which hide most of the webpack configs. I only checked the module.rules config so I came with this. I will double-check other configs.

@alexander-akait
Copy link
Member

Yes, only css-loader touch url/@import in the basic setup

@tianzhich
Copy link
Author

Yes, only css-loader touch url/@import in the basic setup

Yes, but what I am confused about is there was no css-loader in the configs. And after process with sass-loader, the path in the url() was unchanged, but after with postcss-loader, it was touched and modified.

I'm not familiar with webpack like you. Have you ever encountered this? Are there any plugins that touched this? I also fired an issue in the repo of that tool. But if you know that much appreciated.

@alexander-akait
Copy link
Member

Have you ever encountered this?

No

Are there any plugins that touched this?

Yes, for example https://github.com/postcss/postcss-url

@tianzhich
Copy link
Author

I found that they created an additional plugin to touch this...

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

No branches or pull requests

2 participants