Skip to content

Commit

Permalink
fix: hide ext appending behind a flag (ref #1372)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Aug 26, 2018
1 parent 5a7d56d commit f0beed3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ module.exports = function (source) {
// e.g. foo.vue?type=template&id=xxxxx
// and we will return early
if (incomingQuery.type) {
return selectBlock(descriptor, loaderContext, incomingQuery)
return selectBlock(
descriptor,
loaderContext,
incomingQuery,
!!options.appendExtension
)
}

// module id for scoped CSS & hot-reload
Expand Down
19 changes: 15 additions & 4 deletions lib/select.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
module.exports = function selectBlock (descriptor, loaderContext, query) {
module.exports = function selectBlock (
descriptor,
loaderContext,
query,
appendExtension
) {
// template
if (query.type === `template`) {
loaderContext.resourcePath += '.' + (descriptor.template.lang || 'html')
if (appendExtension) {
loaderContext.resourcePath += '.' + (descriptor.template.lang || 'html')
}
loaderContext.callback(
null,
descriptor.template.content,
Expand All @@ -12,7 +19,9 @@ module.exports = function selectBlock (descriptor, loaderContext, query) {

// script
if (query.type === `script`) {
loaderContext.resourcePath += '.' + (descriptor.script.lang || 'js')
if (appendExtension) {
loaderContext.resourcePath += '.' + (descriptor.script.lang || 'js')
}
loaderContext.callback(
null,
descriptor.script.content,
Expand All @@ -24,7 +33,9 @@ module.exports = function selectBlock (descriptor, loaderContext, query) {
// styles
if (query.type === `style` && query.index != null) {
const style = descriptor.styles[query.index]
loaderContext.resourcePath += '.' + (style.lang || 'css')
if (appendExtension) {
loaderContext.resourcePath += '.' + (style.lang || 'css')
}
loaderContext.callback(
null,
style.content,
Expand Down
2 changes: 1 addition & 1 deletion test/style.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,6 @@ test('CSS Modules', async () => {
// custom ident
await testWithIdent(
'[path][name]---[local]---[hash:base64:5]',
/css-modules-vue---red---\w{5}/
/css-modules---red---\w{5}/
)
})

0 comments on commit f0beed3

Please sign in to comment.