From d07e37c1b819e3cd07f69764a75ff67e2b054a95 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 16 Jan 2024 14:52:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(vue2):=20=E6=94=AF=E6=8C=81=E5=8A=A0?= =?UTF-8?q?=E8=BD=BDuts=E6=96=87=E4=BB=B6=EF=BC=88=E5=BE=85=E4=BD=BF?= =?UTF-8?q?=E7=94=A8uts2js=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vue-cli-plugin-uni/lib/configure-webpack.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/vue-cli-plugin-uni/lib/configure-webpack.js b/packages/vue-cli-plugin-uni/lib/configure-webpack.js index e266a54f1d5..0ea856f38d8 100644 --- a/packages/vue-cli-plugin-uni/lib/configure-webpack.js +++ b/packages/vue-cli-plugin-uni/lib/configure-webpack.js @@ -94,16 +94,28 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt const tsLoaderOptions = require('./util').getTsLoadOptions() - function updateTsLoader (rawRules, fakeFile, loader) { + function updateTsLoader (rawRules, fakeFile, loader, appendUTS = false) { const matchRule = rawRules.find(createMatcher(fakeFile)) if (matchRule && matchRule.use) { if (isInHBuilderX) { matchRule.use.forEach(matchUse => { if (matchUse.loader.includes('ts-loader')) { Object.assign(matchUse.options, tsLoaderOptions) + if (appendUTS) { + if (!Array.isArray(matchUse.options.appendTsSuffixTo)) { + matchUse.options.appendTsSuffixTo = [matchUse.options.appendTsSuffixTo] + } + matchUse.options.appendTsSuffixTo.push(/\.uts$/) + } } }) } + if (appendUTS) { + if (!Array.isArray(matchRule.test)) { + matchRule.test = [matchRule.test] + } + matchRule.test.push(/\.uts$/) + } matchRule.use.push(loader) } } @@ -160,7 +172,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt updateTsLoader(rawRules, 'foo.ts', { loader: resolve('packages/webpack-preprocess-loader'), options: jsPreprocessOptions - }) + }, true) updateTsLoader(rawRules, 'foo.tsx', { loader: resolve('packages/webpack-preprocess-loader'), options: jsPreprocessOptions