Skip to content

ignored adding index suffix for 1st <style> for more friendly unit tests #1104

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,13 @@ module.exports = function (content) {
// $2: ?a=b
const query = loaderUtils.parseQuery($2 || '?')
Object.assign(query, OPTIONS, option, DEFAULT_OPTIONS)
if (index !== -1) {
if (index > 0) {
// Note:
// Class name is generated according to its filename.
// Different <style> tags in the same .vue file may generate same names.
// Different `<style>` tags in the same `.vue` file may generate same names.
// Append `_[index]` to class name to avoid this.
// But the 1st `<style>` tag will be ignored from this update.
// See https://github.com/vuejs/vue-loader/issues/703
query.localIdentName += '_' + index
}
return $1 + '?' + JSON.stringify(query)
Expand Down
7 changes: 4 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,17 +620,18 @@ describe('vue-loader', () => {
// default module + pre-processor + scoped
const anotherClassName = instance.$style.red
expect(anotherClassName).to.match(regexToMatch).and.not.equal(className)
expect(anotherClassName).to.match(/_1$/)
expect(anotherClassName).to.equal(className + '_1')
const id = 'data-v-' + genId('css-modules.vue')
expect(style).to.contain('.' + anotherClassName + '[' + id + ']')

cb()
})
}
// default localIdentName
testWithIdent(undefined, /^\w{23}/, () => {
testWithIdent(undefined, /^\w{21,23}/, () => {
// specified localIdentName
const ident = '[path][name]---[local]---[hash:base64:5]'
const regex = /^test-fixtures-css-modules---red---\w{5}/
const regex = /^test-fixtures-css-modules---red---\w{5,7}/
testWithIdent(ident, regex, done)
})
})
Expand Down