Skip to content

Commit

Permalink
fix: should allow chaining with loaders for non-vue files (#1889)
Browse files Browse the repository at this point in the history
Fixes #1879
Fixes #1883
Fixes #1890
  • Loading branch information
JuniorTour authored Oct 26, 2021
1 parent 820d23c commit f32f953
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
6 changes: 0 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ export default function loader(
) {
const loaderContext = this

if (!/\.vue(\.html)?$/.test(loaderContext.resourcePath)) {
// ts-loader does some really weird stuff which causes vue-loader to
// somehow be applied on non-vue files... ignore them
return source
}

// check if plugin is installed
if (
!errorEmitted &&
Expand Down
6 changes: 0 additions & 6 deletions src/templateLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ const TemplateLoader: webpack.loader.Loader = function (source, inMap) {
source = String(source)
const loaderContext = this

if (/\.[jt]sx?$/.test(loaderContext.resourcePath)) {
// ts-loader does some really weird stuff which causes vue-loader to
// somehow be applied on non-vue files... ignore them
return source
}

// although this is not the main vue-loader, we can get access to the same
// vue-loader options because we've set an ident in the plugin and used that
// ident to create the request for this loader in the pitcher.
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/process-custom-file/custom-file.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions test/fixtures/process-custom-file/process-custom-file.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div>
<CustomFile />
</div>
</template>
<script>
import CustomFile from './custom-file.svg'
export default {
components: {
CustomFile
}
}
</script>
18 changes: 18 additions & 0 deletions test/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,21 @@ test('postLoaders support', async () => {
// class="red" -> class="green"
expect(instance.$el.className).toBe('green')
})

// #1879
test('should allow process custom file', async () => {
const { instance } = await mockBundleAndRun({
entry: 'process-custom-file/process-custom-file.vue',
module: {
rules: [
{
test: /\.svg$/,
loader: 'vue-loader',
},
],
},
})

expect(instance.$el.tagName).toBe('DIV')
expect(instance.$el.innerHTML).toMatch('ProcessedCustomFile')
})

0 comments on commit f32f953

Please sign in to comment.