hewking's blog
Author: hewking
Labels: blog
Created: 2025-01-05T12:11:54Z
Link and comments: https://github.com/hewking/blog/issues/46
splitChunks: {
cacheGroups: {
towxml: {
name: 'towxml-common',
priority: 100,
test: /[\\/]towxml[\\/]/,
chunks: 'all',
minChunks: 1,
enforce: true // 强制创建chunk
},
vendors: {
name: 'vendors',
priority: 90,
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
chunks: 'all',
minChunks: 1
},
commons: {
name: 'commons',
priority: 80,
chunks: 'all',
minChunks: 3,
test: /[\\/]node_modules[\\/]/,
maxSize: 300 * 1024
}
}
}
copy: {
patterns: [
{
from: 'src/towxml',
to: 'miniapp/towxml',
ignore: [
'**/index.js', // 只忽略入口JS
'**/parse/**/*.js', // 忽略解析相关JS
'**/render/**/*.js', // 忽略渲染相关JS
'**/*.md',
'**/*.test.*',
'**/demo/**',
'**/node_modules/**',
'**/.git/**'
]
}
]
}
yarn add mp-html
usingComponents: {
'mp-html': '/mp-html/index'
}
chain.merge({
externals: [
{
'mp-html': 'commonjs mp-html'
}
]
});
import React from 'react';
import { View } from '@tarojs/components';
import type { ViewProps } from '@tarojs/components/types/View';
interface Props extends ViewProps {
content: string;
onLinkTap?: (href: string) => void;
}
export default function RichText({ content, style, onLinkTap }: Props) {
return (
<View style={style}>
<mp-html
content={content}
onLinkTap={onLinkTap}
lazyLoad
selectable
useAnchor
/>
</View>
);
}
import { marked } from 'marked';
interface Props extends ViewProps {
content: string;
type?: 'html' | 'markdown';
onLinkTap?: (href: string) => void;
}
export default function RichText({ content, type = 'html', style, onLinkTap }: Props) {
const htmlContent = React.useMemo(() => {
if (type === 'markdown') {
return marked(content);
}
return content;
}, [content, type]);
return (
<View style={style}>
<mp-html
content={htmlContent}
onLinkTap={onLinkTap}
lazyLoad
selectable
useAnchor
/>
</View>
);
}
copy: {
patterns: [
{
from: 'src/mp-html',
to: 'miniapp/mp-html'
}
]
}
优点:
缺点:
优点:
缺点: