Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [taro-webpack5-runner MiniWebpackModule]非官方维护端平台插件,支持引入原生组件混写 #16310

Open
wants to merge 5 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { getMergeLoaderTemplateReg } from '../utils'

describe('getMergeLoaderTemplateReg', () => {
it('should return match current template RegExp', () => {
const input1 = '.xhsml' // 小红书小程序模版后缀
const input2 = '.ksml' // 快手小程序模版后缀
expect(getMergeLoaderTemplateReg(input1)).toEqual(/\.(wxml|axml|ttml|qml|swan|jxml|xhsml)(\?.*)?$/)
expect(getMergeLoaderTemplateReg(input2)).toEqual(/\.(wxml|axml|ttml|qml|swan|jxml|ksml)(\?.*)?$/)
})
})
2 changes: 1 addition & 1 deletion packages/taro-helper/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const processTypeMap: IProcessTypeMap = {
}

export const CSS_EXT: string[] = ['.css', '.scss', '.sass', '.less', '.styl', '.stylus', '.wxss', '.acss']
export const DEFAULT_SUPPORT_TEMPLATE: string[] = ['wxml', 'axml', 'ttml', 'qml', 'swan', 'jxml']
export const SCSS_EXT: string[] = ['.scss']
export const JS_EXT: string[] = ['.js', '.jsx']
export const TS_EXT: string[] = ['.ts', '.tsx']
Expand All @@ -103,7 +104,6 @@ export const REG_IMAGE = /\.(png|jpe?g|gif|bpm|svg|webp)(\?.*)?$/
export const REG_FONT = /\.(woff2?|eot|ttf|otf)(\?.*)?$/
export const REG_JSON = /\.json(\?.*)?$/
export const REG_UX = /\.ux(\?.*)?$/
export const REG_TEMPLATE = /\.(wxml|axml|ttml|qml|swan|jxml)(\?.*)?$/
export const REG_WXML_IMPORT = /<import(.*)?src=(?:(?:'([^']*)')|(?:"([^"]*)"))/gi
export const REG_URL = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i
export const CSS_IMPORT_REG = /@import (["'])(.+?)\1;/g
Expand Down
6 changes: 6 additions & 0 deletions packages/taro-helper/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as path from 'path'
import {
CSS_EXT,
CSS_IMPORT_REG,
DEFAULT_SUPPORT_TEMPLATE,
NODE_MODULES_REG,
PLATFORMS,
processTypeEnum,
Expand Down Expand Up @@ -693,4 +694,9 @@ export function readConfig<T extends IReadConfigOptions> (configPath: string, op
return result
}

export function getMergeLoaderTemplateReg (templ: string) {
const tmepls = [...DEFAULT_SUPPORT_TEMPLATE, templ ? templ?.substring(1) : '']
return new RegExp(`\\.(${tmepls.join('|')})(\\?.*)?$`)
}

export { fs }
4 changes: 2 additions & 2 deletions packages/taro-mini-runner/src/webpack/chain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
chalk,
fs,
getMergeLoaderTemplateReg,
isNodeModule,
recursiveMerge,
REG_CSS,
Expand All @@ -13,7 +14,6 @@ import {
REG_SCRIPTS,
REG_STYLE,
REG_STYLUS,
REG_TEMPLATE,
resolveMainFilePath,
SCRIPT_EXT
} from '@tarojs/helper'
Expand Down Expand Up @@ -427,7 +427,7 @@ export const getModule = (appPath: string, {
},
script: scriptRule,
template: {
test: REG_TEMPLATE,
test: getMergeLoaderTemplateReg(fileType.templ),
use: [getFileLoader([{
useRelativePath: true,
name: (resourcePath: string) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
getMergeLoaderTemplateReg,
isNodeModule,
recursiveMerge,
REG_CSS,
REG_LESS,
REG_SASS_SASS,
REG_SASS_SCSS,
REG_STYLUS,
REG_TEMPLATE
REG_STYLUS
} from '@tarojs/helper'
import { cloneDeep } from 'lodash'
import path from 'path'
Expand Down Expand Up @@ -88,7 +88,7 @@ export class MiniWebpackModule {
script: this.getScriptRule(),

template: {
test: REG_TEMPLATE,
test: getMergeLoaderTemplateReg(fileType.templ),
type: 'asset/resource',
generator: {
filename ({ filename }) {
Expand Down