core icon indicating copy to clipboard operation
core copied to clipboard

feat(compiler-sfc): add preserveTilde option for asset URL and srcset transformations

Open edison1105 opened this issue 4 months ago • 5 comments

close #13460 close https://github.com/vitejs/vite-plugin-vue/issues/15

This PR introduces a new option, preserveTilde, for handling the ~ in asset URLs.

  • The default value is false, which keeps the existing behavior: leading ~ and ~/ are stripped - it's exactly the same as before.
  • If set to true, leading ~ and ~/ are preserved and resolution relies on the bundler (e.g., Vite).

Usage example:

  // vite.config.js
  plugins: [vue({
    template:{
      transformAssetUrls:{
        preserveTilde: true 
      }
    }
  })],

Summary by CodeRabbit

  • New Features
    • Added support for preserving the tilde (~) character in asset URLs and srcset attributes when specified, improving compatibility with certain aliasing setups.
  • Tests
    • Introduced new test cases to verify the behavior of asset URL and srcset transformations when the preserveTilde option is enabled.

edison1105 avatar Jun 11 '25 01:06 edison1105