Skip to content
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

fix: not allow process custom file (fix #1879) #1889

Merged
merged 1 commit into from Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/index.ts
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
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
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
@@ -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
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')
})