- 链接/图片 href/src/alt/title 与代码块 language 属性改用属性级转义 (浏览器环境 escapeHTML 不转义双引号,存在属性注入面) - 修复 title 中反斜杠转义还原,引用链接 title 输出与行内一致 - 产物改用 .mjs/.cjs 扩展名(type:module 下 .js 被 Node 按 ESM 解析, require() 拿不到导出);exports 指向 dist 而非 src TS 源码 - 新增 .gitattributes 强制 LF,避免 Windows CRLF 污染 diff - 配套测试:title/URL/alt/language 注入防护
119 lines
2.5 KiB
JavaScript
119 lines
2.5 KiB
JavaScript
import resolve from '@rollup/plugin-node-resolve';
|
|
import commonjs from '@rollup/plugin-commonjs';
|
|
import terser from '@rollup/plugin-terser';
|
|
import typescript from '@rollup/plugin-typescript';
|
|
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,
|
|
}),
|
|
];
|
|
|
|
const devPlugins = isDev ? [
|
|
serve({
|
|
open: true,
|
|
contentBase: ['site', 'dist'],
|
|
port: 3001,
|
|
}),
|
|
livereload({
|
|
watch: ['src', 'site'],
|
|
}),
|
|
] : [];
|
|
|
|
const terserPlugin = isProd ? [
|
|
terser({
|
|
compress: {
|
|
drop_console: true,
|
|
drop_debugger: true,
|
|
pure_funcs: ['console.log', 'console.warn'],
|
|
},
|
|
format: {
|
|
comments: false,
|
|
},
|
|
}),
|
|
] : [];
|
|
|
|
export default [
|
|
// UMD development
|
|
{
|
|
input: 'src/index.ts',
|
|
output: {
|
|
file: 'dist/metona-editor.js',
|
|
format: 'umd',
|
|
name: 'MeEditor',
|
|
exports: 'named',
|
|
sourcemap: true,
|
|
},
|
|
plugins: [...basePlugins, ...devPlugins],
|
|
},
|
|
// Only build all formats in production
|
|
...(isDev ? [] : [
|
|
// ES Module
|
|
{
|
|
input: 'src/index.ts',
|
|
output: {
|
|
file: 'dist/metona-editor.mjs',
|
|
format: 'es',
|
|
exports: 'named',
|
|
sourcemap: true,
|
|
},
|
|
plugins: basePlugins,
|
|
},
|
|
// CommonJS
|
|
{
|
|
input: 'src/index.ts',
|
|
output: {
|
|
file: 'dist/metona-editor.cjs',
|
|
format: 'cjs',
|
|
exports: 'named',
|
|
sourcemap: true,
|
|
},
|
|
plugins: basePlugins,
|
|
},
|
|
// UMD minified
|
|
{
|
|
input: 'src/index.ts',
|
|
output: {
|
|
file: 'dist/metona-editor.min.js',
|
|
format: 'umd',
|
|
name: 'MeEditor',
|
|
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 declarations bundle
|
|
{
|
|
input: 'src/index.ts',
|
|
output: {
|
|
file: 'dist/metona-editor.d.ts',
|
|
format: 'es',
|
|
},
|
|
plugins: [
|
|
dts(),
|
|
],
|
|
},
|
|
]),
|
|
];
|