- React 适配器子包:@metona-team/metona-toast/react — useToast() hook + 声明式 <Toast /> 组件,组件卸载自动清理;react 为 optional peerDependency,主包保持零依赖 - loading 链式转换改原地 update:id 稳定不重建 DOM,转换后 duration 恢复默认自动关闭;update() 支持 duration 变更动态重启计时器 - _emit 幽灵实例修复:beforeShow 拦截后的 toast 不再注册进 _toasts - dragThreshold 配置项(默认 120px,原硬编码);RTL 容器 dir 属性 + 进度条/side 条/色条镜像 - dedupe 预设插件:相同 type+message 自动去重,支持 uninstall - jest 环境隔离测试独立成 tests/ssr.test.ts(resetModules 不再污染共享模块状态);新增 tests/setup.ts 补 TextEncoder - 文档:README/docs.html 补 React 适配器、dedupe、dragThreshold;CHANGELOG 更新;328 测试全过
137 lines
2.9 KiB
JavaScript
137 lines
2.9 KiB
JavaScript
import resolve from '@rollup/plugin-node-resolve';
|
|
import commonjs from '@rollup/plugin-commonjs';
|
|
import typescript from '@rollup/plugin-typescript';
|
|
import terser from '@rollup/plugin-terser';
|
|
import dts from 'rollup-plugin-dts';
|
|
import serve from 'rollup-plugin-serve';
|
|
import livereload from 'rollup-plugin-livereload';
|
|
|
|
const isDev = process.env.ROLLUP_WATCH;
|
|
const isProd = process.env.NODE_ENV === 'production';
|
|
|
|
// 基础插件
|
|
const basePlugins = [
|
|
resolve(),
|
|
commonjs(),
|
|
typescript({
|
|
tsconfig: './tsconfig.json',
|
|
declaration: false,
|
|
sourceMap: !isProd,
|
|
}),
|
|
];
|
|
|
|
// 开发服务器配置
|
|
const devPlugins = isDev ? [
|
|
serve({
|
|
open: true,
|
|
contentBase: ['site', 'dist'],
|
|
port: 3001,
|
|
}),
|
|
livereload({
|
|
watch: ['src', 'site'],
|
|
}),
|
|
] : [];
|
|
|
|
// 输出配置
|
|
export default [
|
|
// UMD(开发模式)
|
|
{
|
|
input: 'src/index.ts',
|
|
output: {
|
|
file: 'dist/metona-toast.js',
|
|
format: 'umd',
|
|
name: 'MeToast',
|
|
exports: 'named',
|
|
sourcemap: true,
|
|
},
|
|
plugins: [...basePlugins, ...devPlugins],
|
|
},
|
|
// 生产构建(非 dev 模式时输出全格式)
|
|
...(isDev ? [] : [
|
|
// ESM
|
|
{
|
|
input: 'src/index.ts',
|
|
output: {
|
|
file: 'dist/metona-toast.esm.js',
|
|
format: 'es',
|
|
exports: 'named',
|
|
sourcemap: true,
|
|
},
|
|
plugins: basePlugins,
|
|
},
|
|
// CommonJS
|
|
{
|
|
input: 'src/index.ts',
|
|
output: {
|
|
file: 'dist/metona-toast.cjs.js',
|
|
format: 'cjs',
|
|
exports: 'named',
|
|
sourcemap: true,
|
|
},
|
|
plugins: basePlugins,
|
|
},
|
|
// UMD 压缩版
|
|
{
|
|
input: 'src/index.ts',
|
|
output: {
|
|
file: 'dist/metona-toast.min.js',
|
|
format: 'umd',
|
|
name: 'MeToast',
|
|
exports: 'named',
|
|
sourcemap: false,
|
|
},
|
|
plugins: [
|
|
...basePlugins,
|
|
terser({
|
|
compress: {
|
|
drop_console: true,
|
|
drop_debugger: true,
|
|
pure_funcs: ['console.log', 'console.warn'],
|
|
passes: 2,
|
|
},
|
|
format: { comments: false },
|
|
mangle: { toplevel: true },
|
|
}),
|
|
],
|
|
},
|
|
// TypeScript 声明文件合并
|
|
{
|
|
input: 'src/index.ts',
|
|
output: {
|
|
file: 'dist/metona-toast.d.ts',
|
|
format: 'es',
|
|
},
|
|
plugins: [dts()],
|
|
},
|
|
// React 适配器(ESM + CJS),react 为 optional peer 外部依赖
|
|
{
|
|
input: 'src/react.ts',
|
|
external: ['react'],
|
|
output: [
|
|
{
|
|
file: 'dist/react.js',
|
|
format: 'es',
|
|
exports: 'named',
|
|
sourcemap: true,
|
|
},
|
|
{
|
|
file: 'dist/react.cjs.js',
|
|
format: 'cjs',
|
|
exports: 'named',
|
|
sourcemap: true,
|
|
},
|
|
],
|
|
plugins: basePlugins,
|
|
},
|
|
{
|
|
input: 'src/react.ts',
|
|
external: ['react'],
|
|
output: {
|
|
file: 'dist/react.d.ts',
|
|
format: 'es',
|
|
},
|
|
plugins: [dts()],
|
|
},
|
|
]),
|
|
];
|