[go: up one dir, main page]

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 1 commit 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
2 changes: 1 addition & 1 deletion packages/taro-helper/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ 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

export const NODE_MODULES = 'node_modules'
export const NODE_MODULES_REG = /(.*)node_modules/
export const DEFAULT_SUPPORT_TEMPLATE: string[] = ['wxml', 'axml', 'ttml', 'qml', 'swan', 'jxml']

export const PROJECT_CONFIG = 'config/index'

Expand Down
8 changes: 7 additions & 1 deletion packages/taro-helper/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
processTypeMap,
REG_JSON,
SCRIPT_EXT,
TARO_CONFIG_FOLDER
TARO_CONFIG_FOLDER,
DEFAULT_SUPPORT_TEMPLATE
} from './constants'
import { requireWithEsbuild } from './esbuild'
import { chalk } from './terminal'
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
Expand Up @@ -3,6 +3,7 @@ import {
fs,
isNodeModule,
recursiveMerge,
getMergeLoaderTemplateReg,
REG_CSS,
REG_FONT,
REG_IMAGE,
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 {
isNodeModule,
recursiveMerge,
getMergeLoaderTemplateReg,
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