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

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

Open
SoonIter opened this issue Dec 24, 2024 · 1 comment

Comments

@SoonIter
Copy link

SoonIter commented Dec 24, 2024

Bug report

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

module.exports = {
  module: {
    generator: {
      asset: {
        publicPath: '',
      },
    },
    rules: [
      {
        resourceQuery: /raw/,
        type: 'asset/source',
      },
      {
        test: /\.svg$/i,
        oneOf: [
          /* config.module.rule('svg').oneOf('svg-asset-url') */
          {
            type: 'asset/resource',
            resourceQuery: /(__inline=false|url)/,
            generator: {
              filename: 'static/svg/[name].svg',
            },
          },
          /* config.module.rule('svg').oneOf('svg-asset-inline') */
          {
            type: 'asset/inline',
            resourceQuery: /inline/,
          },
          /* 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

@SoonIter SoonIter changed the title [Bug]: [Bug]: wrong path when using generator.publicPath = '' and asset module Dec 24, 2024
@SoonIter
Copy link
Author

It didn't appear in experiments.css in
webpack/webpack#17170

it may related to base_uri replacement logic and importModule result
#915

@SoonIter SoonIter changed the title [Bug]: wrong path when using generator.publicPath = '' and asset module [Bug]: wrong url path when using generator.publicPath = '' and asset module Dec 24, 2024
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

1 participant