Skip to content

experiments.css generate wrong url path #16969

@ahabhgk

Description

@ahabhgk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions