Skip to content

Commit

Permalink
feat(vue2): 支持加载uts文件(待使用uts2js)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Jan 16, 2024
1 parent a92bdb7 commit d07e37c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/vue-cli-plugin-uni/lib/configure-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d07e37c

Please sign in to comment.