From f32f9538ea34fc08e1a28622227896241847690f Mon Sep 17 00:00:00 2001 From: JuniorTour Date: Tue, 26 Oct 2021 10:27:20 +0800 Subject: [PATCH] fix: should allow chaining with loaders for non-vue files (#1889) Fixes #1879 Fixes #1883 Fixes #1890 --- src/index.ts | 6 ------ src/templateLoader.ts | 6 ------ .../process-custom-file/custom-file.svg | 3 +++ .../process-custom-file.vue | 13 +++++++++++++ test/template.spec.ts | 18 ++++++++++++++++++ 5 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 test/fixtures/process-custom-file/custom-file.svg create mode 100644 test/fixtures/process-custom-file/process-custom-file.vue diff --git a/src/index.ts b/src/index.ts index 4a3401f1c..d74373ef5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 && diff --git a/src/templateLoader.ts b/src/templateLoader.ts index b303a383f..c1dd5f400 100644 --- a/src/templateLoader.ts +++ b/src/templateLoader.ts @@ -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. diff --git a/test/fixtures/process-custom-file/custom-file.svg b/test/fixtures/process-custom-file/custom-file.svg new file mode 100644 index 000000000..7edfe0d23 --- /dev/null +++ b/test/fixtures/process-custom-file/custom-file.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/test/fixtures/process-custom-file/process-custom-file.vue b/test/fixtures/process-custom-file/process-custom-file.vue new file mode 100644 index 000000000..842e42d2d --- /dev/null +++ b/test/fixtures/process-custom-file/process-custom-file.vue @@ -0,0 +1,13 @@ + + \ No newline at end of file diff --git a/test/template.spec.ts b/test/template.spec.ts index a16f8f1ef..52eda51cb 100644 --- a/test/template.spec.ts +++ b/test/template.spec.ts @@ -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') +})