vuejs / vue-loader

📦 Webpack loader for Vue.js components
MIT License
4.99k stars 915 forks source link

fix: re-use ident of vue rule for template compiler, fixes #2029 #2030

Closed xanf closed 1 year ago

xanf commented 1 year ago

Webpack 4 uses ident query param underneath to store options objects passed to loaders, and relies on this ident param to retrieve options for correct loaders https://github.com/webpack/webpack/blob/v4.46.0/lib/RuleSet.js#L560-L566

Logic of "identing" is pretty straightforward - if ident is provided in options - that one is respected, but if there is no ident - it is generated based on index of rule in RuleSet

vue-loader heavily modifies rules after normalizeRules kicked in and put ident's for existing rules here & there.

That means that templateLoader rule, will receive ident based on it's position in rules array, but at this point this ident might be occupied by some other loader (and that loader will not be "re-indented" because logic there is to maintain existing idents

Since we're putting old rules lower than templateLoader - when resoving ident --> options we will receive wrong object

To fix this we will be reusing vueLoaderUse ident. This is 100% safe, since our rule after identing will be thrown away so no clash here possible. I was even able to test that :smile:

This should fix #2029