Skip to content

[Bug]: wrong url path when using generator.publicPath and asset module #1118

Closed
@SoonIter

Description

@SoonIter

Bug report

configure webpack with generator.asset.publicPath = '' and assetModule as below

module.exports = {
  module: {
    generator: {
      asset: {
        publicPath: '',
      },
    },
    rules: [
      {
        test: /\.svg$/i,
        oneOf: [
          /* config.module.rule('svg').oneOf('svg-asset') */
          {
            type: 'asset',
            parser: {
              dataUrlCondition: {
                maxSize: 1000,
              },
            },
            generator: {
              filename: 'static/svg/[name].svg',
            },
          },
        ],
      },
}

Actual Behavior

webpack-dist/static/css/index.392c62df.css

.a {
  background: url(../..//static/svg/react.svg);
}

Expected Behavior

.a {
  background: url(../../static/svg/react.svg);
}

How Do We Reproduce?

https://github.com/SoonIter/rspack-css-extract-wrong-path

pnpm i
npm run build # both rspack and webpack
# or npm run build:webpack

Please paste the results of npx webpack-cli info here, and mention other relevant information

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