From 494b01c89a2353abf6bdb017098a9be9546a59f3 Mon Sep 17 00:00:00 2001 From: Zakary Date: Fri, 16 Sep 2022 14:58:04 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix(router):=20loader=20params=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=80=82=E9=85=8D=20multi=20=E6=A8=A1=E5=BC=8F=20fix?= =?UTF-8?q?=20#12417?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-loader/src/h5.ts | 4 ++-- packages/taro-router/src/router/mpa.ts | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/taro-loader/src/h5.ts b/packages/taro-loader/src/h5.ts index 87c13ba669a2..8da901529995 100644 --- a/packages/taro-loader/src/h5.ts +++ b/packages/taro-loader/src/h5.ts @@ -38,7 +38,7 @@ export default function (this: webpack.LoaderContext) { const pxTransformConfig = options.pxTransformConfig const pathDirname = dirname(this.resourcePath) - const pageName = isMultiRouterMode ? join(pathDirname, options.name).replace(options.sourceDir + '/', '') : '' + const pageName = isMultiRouterMode ? join(pathDirname, options.filename).replace(options.sourceDir + '/', '') : '' if (options.bootstrap) { /** NOTE: Webpack Virtual Module plugin doesn't support triggering a rebuild for webpack5, * which can cause "module not found" error when webpack5 cache is enabled. @@ -83,7 +83,7 @@ applyPolyfills().then(function () { const components = options.useHtmlComponents ? compatComponentImport || '' : webComponents const routesConfig = isMultiRouterMode ? `config.routes = [] -config.route = ${genResource(pageName, pages, this, options.name)} +config.route = ${genResource(pageName, pages, this, options.filename)} config.pageName = "${pageName}"` : `config.routes = [ ${config.pages?.map(path => genResource(path, pages, this)).join(',')} ]` diff --git a/packages/taro-router/src/router/mpa.ts b/packages/taro-router/src/router/mpa.ts index 8d5a6b069627..16a790b79ff8 100644 --- a/packages/taro-router/src/router/mpa.ts +++ b/packages/taro-router/src/router/mpa.ts @@ -36,6 +36,9 @@ export async function createMultiRouter ( let element try { element = await pageConfig.load?.() + if (element instanceof Array) { + element = element[0] + } } catch (error) { throw new Error(error) } From efea1047b95b2bc9a500ce172a5f3d18946b3780 Mon Sep 17 00:00:00 2001 From: Zakary Date: Fri, 16 Sep 2022 20:48:14 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(router):=20=E8=A1=A5=E5=85=85=20multi?= =?UTF-8?q?=20=E7=BC=BA=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/config/dev.conf.ts | 16 +++- .../src/config/prod.conf.ts | 13 ++- packages/taro-webpack-runner/src/index.ts | 84 +++++++++++++++++-- .../src/plugins/MainPlugin.ts | 61 ++++++-------- packages/taro-webpack-runner/src/util/app.ts | 44 ++++++++++ .../taro-webpack-runner/src/util/index.ts | 10 ++- 6 files changed, 174 insertions(+), 54 deletions(-) create mode 100644 packages/taro-webpack-runner/src/util/app.ts diff --git a/packages/taro-webpack-runner/src/config/dev.conf.ts b/packages/taro-webpack-runner/src/config/dev.conf.ts index 0181caadc669..ed0ba6c14cec 100644 --- a/packages/taro-webpack-runner/src/config/dev.conf.ts +++ b/packages/taro-webpack-runner/src/config/dev.conf.ts @@ -1,8 +1,10 @@ -import { chalk, recursiveMerge } from '@tarojs/helper' +import { chalk, recursiveMerge, SCRIPT_EXT } from '@tarojs/helper' +import { AppConfig } from '@tarojs/taro' +import { IOption } from '@tarojs/taro/types/compile' import { get, mapValues, merge } from 'lodash' import * as path from 'path' -import { addTrailingSlash, parseHtmlScript } from '../util' +import { addTrailingSlash, getConfigFilePath, getPages, parseHtmlScript } from '../util' import { getCopyWebpackPlugin, getDefinePlugin, @@ -17,9 +19,9 @@ import { import { BuildConfig } from '../util/types' import getBaseChain from './base.conf' -const emptyObj = {} +const emptyObj: IOption = {} -export default function (appPath: string, config: Partial): any { +export default function (appPath: string, config: Partial, appConfig: AppConfig): any { const chain = getBaseChain(appPath, config) const { alias = {}, @@ -119,6 +121,12 @@ export default function (appPath: string, config: Partial): any { ) } if (isMultiRouterMode) { + const frameworkExts = config.frameworkExts || SCRIPT_EXT + const pages = getPages(appConfig.pages, sourceDir, frameworkExts) + delete entry[entryFileName] + pages.forEach(({ name, path }) => { + entry[name] = [getConfigFilePath(path)] + }) merge(plugin, mapValues(entry, (_filePath, entryName) => { return getHtmlWebpackPlugin([recursiveMerge({ filename: `${entryName}.html`, diff --git a/packages/taro-webpack-runner/src/config/prod.conf.ts b/packages/taro-webpack-runner/src/config/prod.conf.ts index a74051c60396..4ad07628003e 100644 --- a/packages/taro-webpack-runner/src/config/prod.conf.ts +++ b/packages/taro-webpack-runner/src/config/prod.conf.ts @@ -1,8 +1,9 @@ -import { chalk, recursiveMerge } from '@tarojs/helper' +import { chalk, recursiveMerge, SCRIPT_EXT } from '@tarojs/helper' +import { AppConfig } from '@tarojs/taro' import { get, mapValues, merge } from 'lodash' import * as path from 'path' -import { addTrailingSlash, emptyObj, parseHtmlScript } from '../util' +import { addTrailingSlash, emptyObj, getConfigFilePath, getPages, parseHtmlScript } from '../util' import { getCopyWebpackPlugin, getCssoWebpackPlugin, @@ -19,7 +20,7 @@ import { import { BuildConfig } from '../util/types' import getBaseChain from './base.conf' -export default function (appPath: string, config: Partial): any { +export default function (appPath: string, config: Partial, appConfig: AppConfig): any { const chain = getBaseChain(appPath, config) const { alias = emptyObj, @@ -122,6 +123,12 @@ export default function (appPath: string, config: Partial): any { ) } if (isMultiRouterMode) { + const frameworkExts = config.frameworkExts || SCRIPT_EXT + const pages = getPages(appConfig.pages, sourceDir, frameworkExts) + delete entry[entryFileName] + pages.forEach(({ name, path }) => { + entry[name] = [getConfigFilePath(path)] + }) merge(plugin, mapValues(entry, (_filePath, entryName) => { return getHtmlWebpackPlugin([recursiveMerge({ filename: `${entryName}.html`, diff --git a/packages/taro-webpack-runner/src/index.ts b/packages/taro-webpack-runner/src/index.ts index 5cc3e3f813af..19c2a4fdd080 100644 --- a/packages/taro-webpack-runner/src/index.ts +++ b/packages/taro-webpack-runner/src/index.ts @@ -1,4 +1,5 @@ import { recursiveMerge } from '@tarojs/helper' +import { AppConfig } from '@tarojs/taro' import * as detectPort from 'detect-port' import * as path from 'path' import { format as formatUrl } from 'url' @@ -9,7 +10,7 @@ import buildConf from './config/build.conf' import devConf from './config/dev.conf' import baseDevServerOption from './config/devServer.conf' import prodConf from './config/prod.conf' -import { formatOpenHost, parsePublicPath } from './util' +import { addHtmlSuffix, addLeadingSlash, formatOpenHost, getAppConfig, getAppEntry, parsePublicPath, stripBasename, stripTrailingSlash } from './util' import { makeConfig } from './util/chain' import { bindDevLogger, bindProdLogger, printBuildError } from './util/logHelper' import { BuildConfig, Func } from './util/types' @@ -23,8 +24,8 @@ export const customizeChain = async (chain, modifyWebpackChainFunc: Func, custom } } -const buildProd = async (appPath: string, config: BuildConfig): Promise => { - const webpackChain = prodConf(appPath, config) +const buildProd = async (appPath: string, config: BuildConfig, appConfig: AppConfig): Promise => { + const webpackChain = prodConf(appPath, config, appConfig) await customizeChain(webpackChain, config.modifyWebpackChain, config.webpackChain) if (typeof config.onWebpackChainReady === 'function') { config.onWebpackChainReady(webpackChain) @@ -65,18 +66,76 @@ const buildProd = async (appPath: string, config: BuildConfig): Promise => }) } -const buildDev = async (appPath: string, config: BuildConfig): Promise => { +const buildDev = async (appPath: string, config: BuildConfig, appConfig: AppConfig): Promise => { const conf = buildConf(config) const routerConfig = config.router || {} const routerMode = routerConfig.mode || 'hash' const routerBasename = routerConfig.basename || '/' const publicPath = parsePublicPath(conf.publicPath) const outputPath = path.join(appPath, conf.outputRoot as string) - const customDevServerOption = (config.devServer || {}) as WebpackDevServer.Configuration - const webpackChain = devConf(appPath, config) + const { proxy: customProxy = [], ...customDevServerOption } = config.devServer || {} + const webpackChain = devConf(appPath, config, appConfig) const onBuildFinish = config.onBuildFinish await customizeChain(webpackChain, config.modifyWebpackChain, config.webpackChain) + const isMultiRouterMode = routerMode === 'multi' + const proxy: WebpackDevServer.Configuration['proxy'] = [] + if (isMultiRouterMode) { + const customRoutes = routerConfig?.customRoutes || {} + const routerBasename = routerConfig.basename || '/' + const getEntriesRoutes = (customRoutes: Record = {}) => { + const conf: string[][] = [] + for (let key in customRoutes) { + const path = customRoutes[key] + key = addLeadingSlash(key) + if (typeof path === 'string') { + conf.push([key, addLeadingSlash(path)]) + } else if (path?.length > 0) { + conf.push(...path.map(p => [key, addLeadingSlash(p)])) + } + } + return conf + } + const bypass = req => { + if (req.headers.accept?.indexOf('html') !== -1) { + const pagePath = stripTrailingSlash(stripBasename(req.path, routerBasename)) + if (pagePath === '') { + return addHtmlSuffix(appConfig.entryPagePath || appConfig.pages?.[0]) + } + + const pageIdx = (appConfig.pages ?? []).findIndex(e => addLeadingSlash(e) === pagePath) + if (pageIdx > -1) { + return addHtmlSuffix(appConfig.pages?.[pageIdx]) + } + + const customRoutesConf = getEntriesRoutes(customRoutes) + const idx = getEntriesRoutes(customRoutes).findIndex(list => list[1] === pagePath) + if (idx > -1) { + // NOTE: 自定义路由 + return addHtmlSuffix(customRoutesConf[idx][0]) + } + } + } + proxy.push({ + context: [routerBasename], + bypass + }) + } + + if (!(customProxy instanceof Array)) { + proxy.push(...Object.entries(customProxy).map(([url, options = {}]) => { + const item: WebpackDevServer.ProxyConfigArrayItem = { + context: [url] + } + if (typeof options === 'string') { + item.target = options + } else { + Object.assign(item, options) + } + return item + })) + } + if (typeof config.onWebpackChainReady === 'function') { config.onWebpackChainReady(webpackChain) } @@ -90,11 +149,16 @@ const buildDev = async (appPath: string, config: BuildConfig): Promise => { from: /./, to: publicPath }] - } + }, + proxy, }, baseDevServerOption, customDevServerOption ) + if (devServerOptions.proxy.length < 1) { + // Note: proxy 不可以为空数组 + delete devServerOptions.proxy + } if (devServerOptions.host === 'localhost') { devServerOptions.useLocalIp = false @@ -179,15 +243,17 @@ const buildDev = async (appPath: string, config: BuildConfig): Promise => { export default async (appPath: string, config: BuildConfig): Promise => { const newConfig: BuildConfig = await makeConfig(config) + const appEntry = await getAppEntry(newConfig.entry, newConfig.entryFileName) + const appConfig = getAppConfig(appEntry) if (newConfig.isWatch) { try { - await buildDev(appPath, newConfig) + await buildDev(appPath, newConfig, appConfig) } catch (e) { console.error(e) } } else { try { - await buildProd(appPath, newConfig) + await buildProd(appPath, newConfig, appConfig) } catch (e) { console.error(e) process.exit(1) diff --git a/packages/taro-webpack-runner/src/plugins/MainPlugin.ts b/packages/taro-webpack-runner/src/plugins/MainPlugin.ts index 4f7e6b6f472f..65870750a8d7 100644 --- a/packages/taro-webpack-runner/src/plugins/MainPlugin.ts +++ b/packages/taro-webpack-runner/src/plugins/MainPlugin.ts @@ -1,7 +1,5 @@ import { FRAMEWORK_MAP, - isEmptyObject, - readConfig, resolveMainFilePath, SCRIPT_EXT } from '@tarojs/helper' @@ -9,6 +7,8 @@ import { AppConfig } from '@tarojs/taro' import { defaults } from 'lodash' import * as path from 'path' +import { getAppConfig, getConfigFilePath, getPages } from '../util' + const PLUGIN_NAME = 'MainPlugin' interface IMainPluginOptions { @@ -75,27 +75,35 @@ export default class MainPlugin { compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { compilation.hooks.normalModuleLoader.tap(PLUGIN_NAME, (_loaderContext, module: any) => { - const { framework, entryFileName, sourceDir, designWidth, deviceRatio, loaderMeta } = this.options + const { framework, entryFileName, sourceDir, designWidth, deviceRatio, loaderMeta, routerConfig } = this.options const { dir, name } = path.parse(module.resource) - if (path.join(dir, name) === this.appEntry) { + const suffixRgx = /\.(boot|config)/ + if (!suffixRgx.test(name)) return + + const filePath = path.join(dir, name).replace(sourceDir + (process.platform === 'win32' ? '\\' : '/'), '') + const pageName = filePath.replace(suffixRgx, '') + const routerMode = routerConfig?.mode || 'hash' + const isMultiRouterMode = routerMode === 'multi' + const isApp = !isMultiRouterMode && pageName === entryFileName + if (isApp || this.pagesConfigList.has(pageName)) { module.loaders.push({ loader: '@tarojs/taro-loader/lib/h5', options: { - framework, - loaderMeta, - entryFileName, - sourceDir, - filename: entryFileName, - pages: this.pagesConfigList, - useHtmlComponents: this.options.useHtmlComponents, config: { router: this.options.routerConfig, ...this.appConfig }, + entryFileName, + filename: name.replace(suffixRgx, ''), + framework, + loaderMeta, + pages: this.pagesConfigList, pxTransformConfig: { designWidth, deviceRatio - } + }, + sourceDir, + useHtmlComponents: this.options.useHtmlComponents } }) } @@ -113,8 +121,7 @@ export default class MainPlugin { } return app } - const appEntryPath = getEntryPath(entry) - return appEntryPath + return getEntryPath(entry) } run () { @@ -124,18 +131,9 @@ export default class MainPlugin { } getPages () { - const appPages = this.appConfig.pages - if (!appPages || !appPages.length) { - throw new Error('全局配置缺少 pages 字段,请检查!') - } - const { frameworkExts } = this.options + const { frameworkExts, sourceDir } = this.options - this.pages = new Set([ - ...appPages.map(item => ({ - name: item, - path: resolveMainFilePath(path.join(this.options.sourceDir, item), frameworkExts) - })) - ]) + this.pages = getPages(this.appConfig.pages, sourceDir, frameworkExts) this.getSubPackages() } @@ -174,21 +172,12 @@ export default class MainPlugin { getPagesConfigList () { const pages = this.pages pages.forEach(({ name, path }) => { - const pageConfigPath = this.getConfigFilePath(path) + const pageConfigPath = getConfigFilePath(path) this.pagesConfigList.set(name, pageConfigPath) }) } getAppConfig () { - const appConfigPath = this.getConfigFilePath(this.appEntry) - const appConfig = readConfig(appConfigPath) - if (isEmptyObject(appConfig)) { - throw new Error('缺少 app 全局配置,请检查!') - } - this.appConfig = appConfig - } - - getConfigFilePath (filePath) { - return resolveMainFilePath(`${filePath.replace(path.extname(filePath), '')}.config`) + this.appConfig = getAppConfig(this.appEntry) } } diff --git a/packages/taro-webpack-runner/src/util/app.ts b/packages/taro-webpack-runner/src/util/app.ts new file mode 100644 index 000000000000..ac70529694b6 --- /dev/null +++ b/packages/taro-webpack-runner/src/util/app.ts @@ -0,0 +1,44 @@ +import { isEmptyObject, readConfig, resolveMainFilePath, SCRIPT_EXT } from '@tarojs/helper' +import * as path from 'path' +import { Entry, EntryFunc } from 'webpack' + +import { emptyObj } from '.' + +export function getConfigFilePath (filePath: string) { + return resolveMainFilePath(`${filePath.replace(path.extname(filePath), '')}.config`) +} + +export function getAppConfig (appEntry: string) { + const appConfigPath = getConfigFilePath(appEntry) + const appConfig = readConfig(appConfigPath) + if (isEmptyObject(appConfig)) { + throw new Error('缺少 app 全局配置,请检查!') + } + + return appConfig +} + +export async function getAppEntry (entry: string | string[] | Entry | EntryFunc = emptyObj, entryFileName = 'app') { + if (typeof entry === 'function') { + return getAppEntry(await entry(), entryFileName) + } else if (Array.isArray(entry) || typeof entry === 'string') { + return getAppEntry({ entryFileName: entry }, entryFileName) + } + const app = entry[entryFileName] + if (Array.isArray(app)) { + return app.filter(item => path.basename(item, path.extname(item)) === entryFileName)[0] + } + return app +} + +export function getPages (appPages?: string[], sourceDir = '', frameworkExts: string[] = SCRIPT_EXT) { + if (!appPages || !appPages.length) { + throw new Error('全局配置缺少 pages 字段,请检查!') + } + return new Set([ + ...appPages.map(item => ({ + name: item, + path: resolveMainFilePath(path.join(sourceDir, item), frameworkExts) + })) + ]) +} diff --git a/packages/taro-webpack-runner/src/util/index.ts b/packages/taro-webpack-runner/src/util/index.ts index 798f6a4bf64a..38b394fea991 100644 --- a/packages/taro-webpack-runner/src/util/index.ts +++ b/packages/taro-webpack-runner/src/util/index.ts @@ -1,8 +1,8 @@ -import { IPostcssOption } from '@tarojs/taro/types/compile' +import { IOption, IPostcssOption } from '@tarojs/taro/types/compile' import { networkInterfaces } from 'os' import * as path from 'path' -export const emptyObj = {} +export const emptyObj: IOption = {} export const emptyTogglableObj = { enable: false, config: {} @@ -14,6 +14,10 @@ export const getRootPath = function () { export const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url) export const addTrailingSlash = (url = '') => (url.charAt(url.length - 1) === '/' ? url : url + '/') +export const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix +export const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substr(prefix.length) : path +export const stripTrailingSlash = (path = '') => (path.charAt(path.length - 1) === '/' ? path.substring(0, path.length - 1) : path) +export const addHtmlSuffix = (path = '') => `${path}.html` export const formatOpenHost = host => { let result = host @@ -55,3 +59,5 @@ export function parseHtmlScript (pxtransformOption: IPostcssOption['pxtransform' const rootValue = baseFontSize / options.deviceRatio[designWidth] * 2 return `!function(n){function f(){var e=n.document.documentElement,w=e.getBoundingClientRect().width,x=${rootValue}*w/${designWidth};e.style.fontSize=x>=${max}?"${max}px":x<=${min}?"${min}px":x+"px"}n.addEventListener("resize",(function(){f()})),f()}(window);` } + +export * from './app' From a3f35f74bdef12e5361a4ec25cea7b10c6aa9155 Mon Sep 17 00:00:00 2001 From: Zakary Date: Tue, 20 Sep 2022 10:43:54 +0800 Subject: [PATCH 3/4] test(snapshot): update --- .../__snapshots__/babel.spec.ts.snap | 19 ++-- .../compiler-macros.spec.ts.snap | 19 ++-- .../__snapshots__/config.spec.ts.snap | 57 ++++++----- .../__snapshots__/css-modules.spec.ts.snap | 38 ++++---- .../__tests__/__snapshots__/nerv.spec.ts.snap | 19 ++-- .../__snapshots__/react.spec.ts.snap | 19 ++-- .../__tests__/__snapshots__/sass.spec.ts.snap | 95 +++++++++++-------- .../__snapshots__/subpackages.spec.ts.snap | 19 ++-- .../__tests__/__snapshots__/ts.spec.ts.snap | 19 ++-- .../__tests__/__snapshots__/vue.spec.ts.snap | 19 ++-- .../__tests__/__snapshots__/vue3.spec.ts.snap | 19 ++-- .../src/__tests__/utils/compiler.ts | 4 +- 12 files changed, 201 insertions(+), 145 deletions(-) diff --git a/packages/taro-webpack-runner/src/__tests__/__snapshots__/babel.spec.ts.snap b/packages/taro-webpack-runner/src/__tests__/__snapshots__/babel.spec.ts.snap index 73792529f533..991062be0613 100644 --- a/packages/taro-webpack-runner/src/__tests__/__snapshots__/babel.spec.ts.snap +++ b/packages/taro-webpack-runner/src/__tests__/__snapshots__/babel.spec.ts.snap @@ -3857,22 +3857,25 @@ exports[`babel should convert do expressions 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -3893,12 +3896,12 @@ exports[`babel should convert do expressions 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); diff --git a/packages/taro-webpack-runner/src/__tests__/__snapshots__/compiler-macros.spec.ts.snap b/packages/taro-webpack-runner/src/__tests__/__snapshots__/compiler-macros.spec.ts.snap index 01462c735d0a..0456e2bc8910 100644 --- a/packages/taro-webpack-runner/src/__tests__/__snapshots__/compiler-macros.spec.ts.snap +++ b/packages/taro-webpack-runner/src/__tests__/__snapshots__/compiler-macros.spec.ts.snap @@ -3852,22 +3852,25 @@ exports[`compiler-macros - defineAppConfig and definePageConfig should read app case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -3888,12 +3891,12 @@ exports[`compiler-macros - defineAppConfig and definePageConfig should read app handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); diff --git a/packages/taro-webpack-runner/src/__tests__/__snapshots__/config.spec.ts.snap b/packages/taro-webpack-runner/src/__tests__/__snapshots__/config.spec.ts.snap index e7ae3cfe7732..a91dc7436c53 100644 --- a/packages/taro-webpack-runner/src/__tests__/__snapshots__/config.spec.ts.snap +++ b/packages/taro-webpack-runner/src/__tests__/__snapshots__/config.spec.ts.snap @@ -3864,22 +3864,25 @@ exports[`config should build from origin and pipe to output 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -3900,12 +3903,12 @@ exports[`config should build from origin and pipe to output 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); @@ -8637,22 +8640,25 @@ I m irrelevant. case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -8673,12 +8679,12 @@ I m irrelevant. handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); @@ -13410,22 +13416,25 @@ exports[`config should resolved alias 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -13446,12 +13455,12 @@ exports[`config should resolved alias 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); diff --git a/packages/taro-webpack-runner/src/__tests__/__snapshots__/css-modules.spec.ts.snap b/packages/taro-webpack-runner/src/__tests__/__snapshots__/css-modules.spec.ts.snap index 266ca8d6739d..86cfd6618475 100644 --- a/packages/taro-webpack-runner/src/__tests__/__snapshots__/css-modules.spec.ts.snap +++ b/packages/taro-webpack-runner/src/__tests__/__snapshots__/css-modules.spec.ts.snap @@ -3881,22 +3881,25 @@ exports[`css modules should use css modules with global mode 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -3917,12 +3920,12 @@ exports[`css modules should use css modules with global mode 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); @@ -8663,22 +8666,25 @@ exports[`css modules should use css modules with module mode 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -8699,12 +8705,12 @@ exports[`css modules should use css modules with module mode 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); diff --git a/packages/taro-webpack-runner/src/__tests__/__snapshots__/nerv.spec.ts.snap b/packages/taro-webpack-runner/src/__tests__/__snapshots__/nerv.spec.ts.snap index 422dd5c8b061..db8d5d4e12a6 100644 --- a/packages/taro-webpack-runner/src/__tests__/__snapshots__/nerv.spec.ts.snap +++ b/packages/taro-webpack-runner/src/__tests__/__snapshots__/nerv.spec.ts.snap @@ -3863,22 +3863,25 @@ exports[`nerv should build nerv app 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -3899,12 +3902,12 @@ exports[`nerv should build nerv app 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); diff --git a/packages/taro-webpack-runner/src/__tests__/__snapshots__/react.spec.ts.snap b/packages/taro-webpack-runner/src/__tests__/__snapshots__/react.spec.ts.snap index c747cabe677d..f4e027da88c9 100644 --- a/packages/taro-webpack-runner/src/__tests__/__snapshots__/react.spec.ts.snap +++ b/packages/taro-webpack-runner/src/__tests__/__snapshots__/react.spec.ts.snap @@ -3864,22 +3864,25 @@ exports[`react should build react app 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -3900,12 +3903,12 @@ exports[`react should build react app 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); diff --git a/packages/taro-webpack-runner/src/__tests__/__snapshots__/sass.spec.ts.snap b/packages/taro-webpack-runner/src/__tests__/__snapshots__/sass.spec.ts.snap index 9506ad1a6637..abdf429d9e78 100644 --- a/packages/taro-webpack-runner/src/__tests__/__snapshots__/sass.spec.ts.snap +++ b/packages/taro-webpack-runner/src/__tests__/__snapshots__/sass.spec.ts.snap @@ -3849,22 +3849,25 @@ exports[`sass should build app with sass 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -3885,12 +3888,12 @@ exports[`sass should build app with sass 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); @@ -8608,22 +8611,25 @@ exports[`sass should build app with scss 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -8644,12 +8650,12 @@ exports[`sass should build app with scss 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); @@ -13377,22 +13383,25 @@ exports[`sass should set global sass content with data 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -13413,12 +13422,12 @@ exports[`sass should set global sass content with data 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); @@ -18146,22 +18155,25 @@ exports[`sass should set global sass content with source & dir 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -18182,12 +18194,12 @@ exports[`sass should set global sass content with source & dir 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); @@ -22915,22 +22927,25 @@ exports[`sass should set global sass content with source 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -22951,12 +22966,12 @@ exports[`sass should set global sass content with source 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); diff --git a/packages/taro-webpack-runner/src/__tests__/__snapshots__/subpackages.spec.ts.snap b/packages/taro-webpack-runner/src/__tests__/__snapshots__/subpackages.spec.ts.snap index 0284123b8023..cd869d57c670 100644 --- a/packages/taro-webpack-runner/src/__tests__/__snapshots__/subpackages.spec.ts.snap +++ b/packages/taro-webpack-runner/src/__tests__/__snapshots__/subpackages.spec.ts.snap @@ -3927,22 +3927,25 @@ exports[`subpackages should process subpackages 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -3963,12 +3966,12 @@ exports[`subpackages should process subpackages 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(9); diff --git a/packages/taro-webpack-runner/src/__tests__/__snapshots__/ts.spec.ts.snap b/packages/taro-webpack-runner/src/__tests__/__snapshots__/ts.spec.ts.snap index ca5e0194d702..6d60ee2d690e 100644 --- a/packages/taro-webpack-runner/src/__tests__/__snapshots__/ts.spec.ts.snap +++ b/packages/taro-webpack-runner/src/__tests__/__snapshots__/ts.spec.ts.snap @@ -3867,22 +3867,25 @@ exports[`typescript should build project with ts 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -3903,12 +3906,12 @@ exports[`typescript should build project with ts 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(8); diff --git a/packages/taro-webpack-runner/src/__tests__/__snapshots__/vue.spec.ts.snap b/packages/taro-webpack-runner/src/__tests__/__snapshots__/vue.spec.ts.snap index 296a725fee91..087c8e24aca1 100644 --- a/packages/taro-webpack-runner/src/__tests__/__snapshots__/vue.spec.ts.snap +++ b/packages/taro-webpack-runner/src/__tests__/__snapshots__/vue.spec.ts.snap @@ -3821,22 +3821,25 @@ exports[`vue should build vue app 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -3857,12 +3860,12 @@ exports[`vue should build vue app 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(4); diff --git a/packages/taro-webpack-runner/src/__tests__/__snapshots__/vue3.spec.ts.snap b/packages/taro-webpack-runner/src/__tests__/__snapshots__/vue3.spec.ts.snap index 9af6703ed745..8aec369039cb 100644 --- a/packages/taro-webpack-runner/src/__tests__/__snapshots__/vue3.spec.ts.snap +++ b/packages/taro-webpack-runner/src/__tests__/__snapshots__/vue3.spec.ts.snap @@ -3760,22 +3760,25 @@ exports[`vue3 should build vue3 app 2`] = ` case 10: element = _context.sent; - _context.next = 16; + if (element instanceof Array) { + element = element[0]; + } + _context.next = 17; break; - case 13: - _context.prev = 13; + case 14: + _context.prev = 14; _context.t0 = _context[\\"catch\\"](7); throw new Error(_context.t0); - case 16: + case 17: if (element) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt(\\"return\\"); - case 18: + case 19: enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false; undefined.trigger(\\"__taroRouterChange\\", { \\"toLocation\\": { @@ -3796,12 +3799,12 @@ exports[`vue3 should build vue3 app 2`] = ` handler.load(page, pageConfig); (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam); - case 28: + case 29: case \\"end\\": return _context.stop(); } } - }), _callee, null, [ [ 7, 13 ] ]); + }), _callee, null, [ [ 7, 14 ] ]); }))); } var path_to_regexp = __webpack_require__(4); diff --git a/packages/taro-webpack-runner/src/__tests__/utils/compiler.ts b/packages/taro-webpack-runner/src/__tests__/utils/compiler.ts index dd8a28eac6a1..292075517eca 100644 --- a/packages/taro-webpack-runner/src/__tests__/utils/compiler.ts +++ b/packages/taro-webpack-runner/src/__tests__/utils/compiler.ts @@ -9,6 +9,7 @@ import * as merge from 'webpack-merge' import prodConf from '../../config/prod.conf' import { customizeChain } from '../../index' +import { getAppConfig, getAppEntry } from '../../util' import { makeConfig } from '../../util/chain' import { BuildConfig } from '../../util/types' import baseConfig from './config' @@ -112,7 +113,8 @@ export async function compile (app: string, customConfig: Partial = }, customConfig) const newConfig: BuildConfig = await makeConfig(config) - const webpackChain = prodConf(appPath, newConfig) + const entry = await getAppEntry(newConfig.entry) + const webpackChain = prodConf(appPath, newConfig, getAppConfig(entry)) await customizeChain(webpackChain, () => {}, newConfig.webpackChain) From 99eb448f3c1c870380bd119da1e7ebf7493eb665 Mon Sep 17 00:00:00 2001 From: Zakary Date: Tue, 20 Sep 2022 13:59:31 +0800 Subject: [PATCH 4/4] fix(test): update cli babel check --- packages/taro-cli/jest.config.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/taro-cli/jest.config.js b/packages/taro-cli/jest.config.js index 7e94be850b30..1da65c2847d5 100644 --- a/packages/taro-cli/jest.config.js +++ b/packages/taro-cli/jest.config.js @@ -1,11 +1,22 @@ +const { jsWithTs: tsjPreset } = require('ts-jest/presets') + module.exports = { - preset: 'ts-jest', - testEnvironment: 'node', - moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'jsx', 'node'], - testMatch: ['**/__tests__/?(*.)+(spec|test).[jt]s?(x)'], globals: { 'ts-jest': { diagnostics: false - } - } + }, + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'jsx', 'node'], + preset: 'ts-jest', + testEnvironment: 'node', + testMatch: ['**/__tests__/?(*.)+(spec|test).[jt]s?(x)'], + testTimeout: 60000, + transform: { + '^.+\\.jsx?$': [ require.resolve('babel-jest'), { rootMode: 'upward' } ], + '^.+\\.tsx?$': 'ts-jest', + ...tsjPreset.transform + }, + transformIgnorePatterns: [ + 'node_modules', + ], }