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

experiments.css generate wrong url path #16969

Closed
ahabhgk opened this issue Apr 12, 2023 · 1 comment · May be fixed by #17170
Closed

experiments.css generate wrong url path #16969

ahabhgk opened this issue Apr 12, 2023 · 1 comment · May be fixed by #17170

Comments

@ahabhgk
Copy link
Contributor

ahabhgk commented Apr 12, 2023

Bug report

Case 1: publicPath is not "auto"

What is the current behavior?

With following webpack config:

// webpack.config.js
module.exports = {
  entry: 'index.css',
  output: {
    publicPath: 'aaa.com/aa/',
  },
  module: {
    rules: [{ test: /\.png$/, type: 'asset/resource' }],
  },
  experiments: {
    css: true,
  },
}
/* index.css */
.a {
  background-image: url(./bg.png);
}

will generate:

.foo {
  background-image: url(bg.png); /* <-- wrong */
}
head{--webpack-main:\.\/index\.css;}

What is the expected behavior?

It should generate:

.foo {
  background-image: url(aaa.com/aa/bg.png);
}
head{--webpack-main:\.\/index\.css;}

Case 2: publicPath is "auto"

What is the current behavior?

With following webpack config:

// webpack.config.js
module.exports = {
  entry: 'index.css',
  output: {
    // publicPath: "auto" is default value
    cssFilename: 'css/[name].css',
    assetModuleFilename: 'assets/[name][ext]',
  },
  module: {
    rules: [{ test: /\.png$/, type: 'asset/resource' }],
  },
  experiments: {
    css: true,
  },
}
/* index.css */
.a {
  background-image: url(./bg.png);
}

will generate:

.foo {
  background-image: url(assets/bg.png); /* <-- wrong */
}
head{--webpack-main:\.\/index\.css;}

What is the expected behavior?

It should generate:

.foo {
  background-image: url(../assets/bg.png);
}
head{--webpack-main:\.\/index\.css;}

Other relevant information:
webpack version: 5.76.3
Node.js version: 18
Operating System: osx

@ahabhgk ahabhgk changed the title experiments.css generate wrong url path when output.publicPath is set experiments.css generate wrong url path Apr 12, 2023
@alexander-akait
Copy link
Member

Thank you for report, I will move it inside #14893, because it is still under experiments, we can have many 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 a pull request may close this issue.

2 participants