From 1607fb8d71986e3a499618a464208ece2c7237a6 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 22 Sep 2021 18:21:31 -0400 Subject: [PATCH 1/7] chore: changelog [ci skip] --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fbb1baf9..4dcf6bbe4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,26 @@ +## [16.8.1](https://github.com/vuejs/vue-loader/compare/v16.8.0...v16.8.1) (2021-09-22) + + +### Bug Fixes + +* fix template options resolving for ts ([91f581b](https://github.com/vuejs/vue-loader/commit/91f581b99644119b68e586a0b642fff3811c8741)) + + + +# [16.8.0](https://github.com/vuejs/vue-loader/compare/v16.7.1...v16.8.0) (2021-09-22) + + +### Bug Fixes + +* **hmr:** fix hmr regression ([bacc6a9](https://github.com/vuejs/vue-loader/commit/bacc6a9eeca40d6028a2d9a5f6ee02e6c8574abd)) + + +### Features + +* enableTsInTemplate option ([7613534](https://github.com/vuejs/vue-loader/commit/7613534954b83489a060860b9525a0d121023c5b)) + + + # [16.8.0](https://github.com/vuejs/vue-loader/compare/v16.7.1...v16.8.0) (2021-09-22) From 8ed3af4dde72e87570e071c34f7f3760bd0cc540 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 22 Sep 2021 18:22:42 -0400 Subject: [PATCH 2/7] chore: changelog fix [ci skip] --- CHANGELOG.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dcf6bbe4..972c72248 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,22 +5,6 @@ * fix template options resolving for ts ([91f581b](https://github.com/vuejs/vue-loader/commit/91f581b99644119b68e586a0b642fff3811c8741)) - - -# [16.8.0](https://github.com/vuejs/vue-loader/compare/v16.7.1...v16.8.0) (2021-09-22) - - -### Bug Fixes - -* **hmr:** fix hmr regression ([bacc6a9](https://github.com/vuejs/vue-loader/commit/bacc6a9eeca40d6028a2d9a5f6ee02e6c8574abd)) - - -### Features - -* enableTsInTemplate option ([7613534](https://github.com/vuejs/vue-loader/commit/7613534954b83489a060860b9525a0d121023c5b)) - - - # [16.8.0](https://github.com/vuejs/vue-loader/compare/v16.7.1...v16.8.0) (2021-09-22) From 63fdf8dfd1c0c87bd04131e93cbda5138721daab Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Thu, 23 Sep 2021 08:56:38 +0800 Subject: [PATCH 3/7] chore: remove duplicate entries from changelog --- CHANGELOG.md | 49 +------------------------------------------------ 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 972c72248..c0117d045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,25 +29,6 @@ * remove pure annotation for custom blocks ([cd891e5](https://github.com/vuejs/vue-loader/commit/cd891e593bf7f8aff852f1d47fda2337de661bea)) - -## [16.7.1](https://github.com/vuejs/vue-loader/compare/v16.7.0...v16.7.1) (2021-09-22) - - -### Bug Fixes - -* remove pure annotation for custom blocks ([cd891e5](https://github.com/vuejs/vue-loader/commit/cd891e593bf7f8aff852f1d47fda2337de661bea)) - - - -# [16.7.0](https://github.com/vuejs/vue-loader/compare/v16.6.0...v16.7.0) (2021-09-21) - - -### Features - -* support optional @vue/compiler-sfc peer dep ([21725a4](https://github.com/vuejs/vue-loader/commit/21725a4ebc9c8d7f8a590d700017759327e21c2e)) - - - # [16.7.0](https://github.com/vuejs/vue-loader/compare/v16.6.0...v16.7.0) (2021-09-21) @@ -56,21 +37,6 @@ * support optional @vue/compiler-sfc peer dep ([21725a4](https://github.com/vuejs/vue-loader/commit/21725a4ebc9c8d7f8a590d700017759327e21c2e)) - -# [16.6.0](https://github.com/vuejs/vue-loader/compare/v16.5.0...v16.6.0) (2021-09-20) - - -### Bug Fixes - -* generate treeshaking friendly code ([11e3cb8](https://github.com/vuejs/vue-loader/commit/11e3cb8a8a4a4e0aedc2978ce6d7e549a61de3d7)) - - -### Features - -* support ts in template expressions ([573fbd2](https://github.com/vuejs/vue-loader/commit/573fbd2e72c3246c2daadb8d8c053464c964cfe3)) - - - # [16.6.0](https://github.com/vuejs/vue-loader/compare/v16.5.0...v16.6.0) (2021-09-20) @@ -84,25 +50,12 @@ * support ts in template expressions ([573fbd2](https://github.com/vuejs/vue-loader/commit/573fbd2e72c3246c2daadb8d8c053464c964cfe3)) - -# [16.5.0](https://github.com/vuejs/vue-loader/compare/v16.4.1...v16.5.0) (2021-08-07) - - - # [16.5.0](https://github.com/vuejs/vue-loader/compare/v16.4.1...v16.5.0) (2021-08-07) * Custom Elements mode behavior changed: now only inlines the CSS and no longer exports the custom element constructor (exports the component as in normal mode). Users now need to explicitly call `defineCustomElement` on the component. This allows the custom element to be defined using an async version of the source component. -## [16.4.1](https://github.com/vuejs/vue-loader/compare/v16.4.0...v16.4.1) (2021-08-02) - - -### Bug Fixes - -* fix webpack 5.48 compatibility ([b94289c](https://github.com/vuejs/vue-loader/commit/b94289c9fb395556100ec121529dfe676280d3cd)), closes [#1859](https://github.com/vuejs/vue-loader/issues/1859) - - -## [16.4.1](https://github.com/vuejs/vue-loader/compare/v16.3.3...v16.4.1) (2021-08-02) +## [16.4.1](https://github.com/vuejs/vue-loader/compare/v16.4.0...v16.4.1) (2021-08-02) ### Bug Fixes From 2eccc0efdfbb021fca01fa7d1fbc462c3259e4b6 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Thu, 23 Sep 2021 09:55:25 +0800 Subject: [PATCH 4/7] refactor: use `import type` Now that we don't depend on `@vue/compiler-sfc` directly, we should only import types from the package, in case of accidentally depending on the unlisted dependency. --- src/descriptorCache.ts | 2 +- src/formatError.ts | 2 +- src/index.ts | 2 +- src/pluginWebpack4.ts | 2 +- src/pluginWebpack5.ts | 4 ++-- src/resolveScript.ts | 4 ++-- src/select.ts | 6 +++--- src/templateLoader.ts | 2 +- src/util.ts | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/descriptorCache.ts b/src/descriptorCache.ts index c8df638a7..4c592a0d1 100644 --- a/src/descriptorCache.ts +++ b/src/descriptorCache.ts @@ -1,5 +1,5 @@ import * as fs from 'fs' -import { SFCDescriptor } from '@vue/compiler-sfc' +import type { SFCDescriptor } from '@vue/compiler-sfc' import { compiler } from './compiler' const cache = new Map() diff --git a/src/formatError.ts b/src/formatError.ts index 6ff42aabd..44ea88b66 100644 --- a/src/formatError.ts +++ b/src/formatError.ts @@ -1,4 +1,4 @@ -import { CompilerError } from '@vue/compiler-sfc' +import type { CompilerError } from '@vue/compiler-sfc' import { compiler } from './compiler' import chalk = require('chalk') diff --git a/src/index.ts b/src/index.ts index c93a3c433..4a3401f1c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import * as loaderUtils from 'loader-utils' import hash = require('hash-sum') import { compiler } from './compiler' -import { +import type { TemplateCompiler, CompilerOptions, SFCBlock, diff --git a/src/pluginWebpack4.ts b/src/pluginWebpack4.ts index f4a7f5107..de9841bb3 100644 --- a/src/pluginWebpack4.ts +++ b/src/pluginWebpack4.ts @@ -1,6 +1,6 @@ import * as qs from 'querystring' import webpack = require('webpack') -import { VueLoaderOptions } from './' +import type { VueLoaderOptions } from './' const RuleSet = require('webpack/lib/RuleSet') diff --git a/src/pluginWebpack5.ts b/src/pluginWebpack5.ts index 0334c4bff..6cb83945b 100644 --- a/src/pluginWebpack5.ts +++ b/src/pluginWebpack5.ts @@ -1,6 +1,6 @@ import * as qs from 'querystring' -import { VueLoaderOptions } from './' -import { RuleSetRule, Compiler, Plugin } from 'webpack' +import type { VueLoaderOptions } from './' +import type { RuleSetRule, Compiler, Plugin } from 'webpack' const id = 'vue-loader-plugin' const NS = 'vue-loader' diff --git a/src/resolveScript.ts b/src/resolveScript.ts index 51b0c5aa7..a606d7669 100644 --- a/src/resolveScript.ts +++ b/src/resolveScript.ts @@ -1,10 +1,10 @@ import webpack = require('webpack') -import { +import type { SFCDescriptor, SFCScriptBlock, TemplateCompiler, } from '@vue/compiler-sfc' -import { VueLoaderOptions } from 'src' +import type { VueLoaderOptions } from 'src' import { resolveTemplateTSOptions } from './util' import { compiler } from './compiler' diff --git a/src/select.ts b/src/select.ts index bde198c40..f8e5b796c 100644 --- a/src/select.ts +++ b/src/select.ts @@ -1,8 +1,8 @@ import webpack = require('webpack') -import { SFCDescriptor } from '@vue/compiler-sfc' -import { ParsedUrlQuery } from 'querystring' +import type { SFCDescriptor } from '@vue/compiler-sfc' +import type { ParsedUrlQuery } from 'querystring' import { resolveScript } from './resolveScript' -import { VueLoaderOptions } from 'src' +import type { VueLoaderOptions } from 'src' export function selectBlock( descriptor: SFCDescriptor, diff --git a/src/templateLoader.ts b/src/templateLoader.ts index 2129ad95e..b303a383f 100644 --- a/src/templateLoader.ts +++ b/src/templateLoader.ts @@ -3,7 +3,7 @@ import * as qs from 'querystring' import * as loaderUtils from 'loader-utils' import { VueLoaderOptions } from './' import { formatError } from './formatError' -import { TemplateCompiler } from '@vue/compiler-sfc' +import type { TemplateCompiler } from '@vue/compiler-sfc' import { getDescriptor } from './descriptorCache' import { resolveScript } from './resolveScript' import { resolveTemplateTSOptions } from './util' diff --git a/src/util.ts b/src/util.ts index 1387982c5..2e467b9d6 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,5 +1,5 @@ -import { SFCDescriptor, CompilerOptions } from '@vue/compiler-sfc' -import { VueLoaderOptions } from '.' +import type { SFCDescriptor, CompilerOptions } from '@vue/compiler-sfc' +import type { VueLoaderOptions } from '.' export function resolveTemplateTSOptions( descriptor: SFCDescriptor, From 820d23cbf16013dae894e0d84ed9da6e58a37584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sevil=20Y=C4=B1lmaz?= Date: Sun, 10 Oct 2021 10:31:35 +0200 Subject: [PATCH 5/7] fix(plugin): use compiler.webpack when possible (#1884) --- src/pluginWebpack5.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pluginWebpack5.ts b/src/pluginWebpack5.ts index 6cb83945b..0ffec99e5 100644 --- a/src/pluginWebpack5.ts +++ b/src/pluginWebpack5.ts @@ -98,14 +98,16 @@ class VueLoaderPlugin implements Plugin { static NS = NS apply(compiler: Compiler) { + // @ts-ignore + const normalModule = compiler.webpack.NormalModule || NormalModule + // add NS marker so that the loader can detect and report missing plugin compiler.hooks.compilation.tap(id, (compilation) => { - NormalModule.getCompilationHooks(compilation).loader.tap( - id, - (loaderContext: any) => { + normalModule + .getCompilationHooks(compilation) + .loader.tap(id, (loaderContext: any) => { loaderContext[NS] = true - } - ) + }) }) const rules = compiler.options.module!.rules From f32f9538ea34fc08e1a28622227896241847690f Mon Sep 17 00:00:00 2001 From: JuniorTour Date: Tue, 26 Oct 2021 10:27:20 +0800 Subject: [PATCH 6/7] 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') +}) From a0243bd9cca85d2d84e9e767059512c62f52aabd Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 26 Oct 2021 10:56:57 +0800 Subject: [PATCH 7/7] 16.8.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 85c2b2301..7895ffc66 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-loader", - "version": "16.8.1", + "version": "16.8.2", "license": "MIT", "author": "Evan You", "main": "dist/index.js",