From 3222451614e8c5e4c1c3188bd6388285a25851ba Mon Sep 17 00:00:00 2001 From: underfin <2218301630@qq.com> Date: Fri, 31 Jul 2020 00:11:25 +0800 Subject: [PATCH] fix: support options for template block preprocessor render (#377) also bump vue-compiler deps --- package.json | 2 +- src/index.ts | 12 ++++++++++- yarn.lock | 58 ++++++++++++++++++++++++++-------------------------- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 61bceb9..a7e6a55 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@types/debug": "^4.1.5", "@types/jest": "^25.2.3", "@types/node": "^13.13.2", - "@vue/compiler-sfc": "^3.0.0-beta.22", + "@vue/compiler-sfc": "^3.0.0-rc.5", "husky": "^4.2.0", "jest": "^26.0.1", "lint-staged": "^10.1.7", diff --git a/src/index.ts b/src/index.ts index c819a6b..81a02db 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,6 +42,10 @@ export interface Options { preprocessStyles?: boolean // sfc template options + templatePreprocessOptions?: Record< + string, + SFCTemplateCompileOptions['preprocessOptions'] + > compiler?: SFCTemplateCompileOptions['compiler'] compilerOptions?: SFCTemplateCompileOptions['compilerOptions'] transformAssetUrls?: SFCTemplateCompileOptions['transformAssetUrls'] @@ -142,11 +146,17 @@ export default function PluginVue(userOptions: Partial = {}): Plugin { if (query.type === 'template') { debug(`transform(${id})`) const block = descriptor.template! + const preprocessLang = block.lang + const preprocessOptions = + preprocessLang && + options.templatePreprocessOptions && + options.templatePreprocessOptions[preprocessLang] const result = compileTemplate({ filename: query.filename, source: code, inMap: query.src ? undefined : block.map, - preprocessLang: block.lang, + preprocessLang, + preprocessOptions, preprocessCustomRequire: options.preprocessCustomRequire, compiler: options.compiler, ssr: isServer, diff --git a/yarn.lock b/yarn.lock index b2c2424..baa54cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -643,36 +643,36 @@ dependencies: "@types/yargs-parser" "*" -"@vue/compiler-core@3.0.0-beta.22": - version "3.0.0-beta.22" - resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.0.0-beta.22.tgz#d49acac2125d5e54fcf6958402ad449e2587c540" - integrity sha512-i/e965dQbJ4EGkX53a/aBO//IjgG5Rl9LOoRh91ZmPxi44WSG+tu+mvq+y7lRl5HoxkjGWo8GVErFYSRQnSLPA== +"@vue/compiler-core@3.0.0-rc.5": + version "3.0.0-rc.5" + resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.0.0-rc.5.tgz#dd4f1816fcae34a81bc60e584f97993cad284d54" + integrity sha512-dNz5AObEYg0Oglw3emIsBhTAOVfObrfxDaAzR0UTRDDq+Ohfr6KTSaVQAH88Ym+oa08ZlLZBFc6ARe9doAOIxg== dependencies: "@babel/parser" "^7.10.4" "@babel/types" "^7.10.4" - "@vue/shared" "3.0.0-beta.22" + "@vue/shared" "3.0.0-rc.5" estree-walker "^2.0.1" source-map "^0.6.1" -"@vue/compiler-dom@3.0.0-beta.22": - version "3.0.0-beta.22" - resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.0.0-beta.22.tgz#d3eae4321767529ca73f93a1ddb378f53e5728b4" - integrity sha512-kJCEeyaBbS+VjYNFEi3o2mnwS2rqdthpQ6TNigojXmGKEoA3UCOrn3IGR3iTSdo/3knaoA9/zwJ8LcxSXkZXMg== +"@vue/compiler-dom@3.0.0-rc.5": + version "3.0.0-rc.5" + resolved "https://registry.yarnpkg.com/@vue/compiler-dom/-/compiler-dom-3.0.0-rc.5.tgz#83905e8601123a3654b90fbd80708a16530ce21a" + integrity sha512-z8n+R1GhFnWuKURLYxfVSEfP7nSNM91qteobxwys55fhlZZuReouMnUwgrn+ois/IL6RdFlT9H+n4+N6yLrdJA== dependencies: - "@vue/compiler-core" "3.0.0-beta.22" - "@vue/shared" "3.0.0-beta.22" + "@vue/compiler-core" "3.0.0-rc.5" + "@vue/shared" "3.0.0-rc.5" -"@vue/compiler-sfc@^3.0.0-beta.22": - version "3.0.0-beta.22" - resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.0.0-beta.22.tgz#14694b57b78c7332d7c65084395b5eb457241be6" - integrity sha512-G2ex92dbhrsshQV38SrPKwlvBi3kNqxXs2yJ49OojPxuQrH/ndcLHeFaiuK2T6W796xHMBesGCsS8AmHFNuOBg== +"@vue/compiler-sfc@^3.0.0-rc.5": + version "3.0.0-rc.5" + resolved "https://registry.yarnpkg.com/@vue/compiler-sfc/-/compiler-sfc-3.0.0-rc.5.tgz#374e52a6fbf8fb9aee1213026050a0f1c496fecf" + integrity sha512-huoIFEfFCJxHcpoByAUQti7CIwJdHPLJXKuy2HG7J1B+IEKugtBdF50CLH35ZD8dWM0nyOMFFqTbO7i6CCjL3Q== dependencies: "@babel/parser" "^7.10.4" "@babel/types" "^7.10.4" - "@vue/compiler-core" "3.0.0-beta.22" - "@vue/compiler-dom" "3.0.0-beta.22" - "@vue/compiler-ssr" "3.0.0-beta.22" - "@vue/shared" "3.0.0-beta.22" + "@vue/compiler-core" "3.0.0-rc.5" + "@vue/compiler-dom" "3.0.0-rc.5" + "@vue/compiler-ssr" "3.0.0-rc.5" + "@vue/shared" "3.0.0-rc.5" consolidate "^0.15.1" estree-walker "^2.0.1" hash-sum "^2.0.0" @@ -684,18 +684,18 @@ postcss-selector-parser "^6.0.2" source-map "^0.6.1" -"@vue/compiler-ssr@3.0.0-beta.22": - version "3.0.0-beta.22" - resolved "https://registry.yarnpkg.com/@vue/compiler-ssr/-/compiler-ssr-3.0.0-beta.22.tgz#98f42e44f1d83f336dfa26613f6e0a2e07ec43a2" - integrity sha512-v4Va4ODKV1OO0Vn+Xm9C7btZeNyerkrGxJ+s4Rd8szDN92TVHEvQUQymwVvUf7nzdS2Jf8K/8r1xz++xOaOPxQ== +"@vue/compiler-ssr@3.0.0-rc.5": + version "3.0.0-rc.5" + resolved "https://registry.yarnpkg.com/@vue/compiler-ssr/-/compiler-ssr-3.0.0-rc.5.tgz#878406c59daff362ecdcb199fb9467a769ca8de5" + integrity sha512-OU5Vl2+bCDMImS9OeCVnl4lfxZ3/sopdwX2SrUWVKQvCxmmmlyWvoVkC6nNGCs/MrOmIMhKmL6etgzLTWyCkUg== dependencies: - "@vue/compiler-dom" "3.0.0-beta.22" - "@vue/shared" "3.0.0-beta.22" + "@vue/compiler-dom" "3.0.0-rc.5" + "@vue/shared" "3.0.0-rc.5" -"@vue/shared@3.0.0-beta.22": - version "3.0.0-beta.22" - resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.0.0-beta.22.tgz#b5c40f27f9fbb76f235255d836c3226566ae9652" - integrity sha512-LX/unRMM9QUGIQjR9v2pKy60MRXWQRVEgaL6R8nFSRkbx2TTmShIdqmQPgciQwEBe7n5hsdZcSms+8LepNEykg== +"@vue/shared@3.0.0-rc.5": + version "3.0.0-rc.5" + resolved "https://registry.yarnpkg.com/@vue/shared/-/shared-3.0.0-rc.5.tgz#cea2378e3e37363ddc1f5dd158edc9c9b5b3fff0" + integrity sha512-ZhcgGzBpp+pUzisZgQpM4ctIGgLpYjBj7/rZfbhEPxFHF/BuTV2jmhXvAl8aF9xDAejIcw85xCy92gDSwKtPag== abab@^2.0.3: version "2.0.3"