Skip to content

Commit cdb2832

Browse files
committed
refactor: 修改为默认导出并启用内置插件
1 parent 6cb08d9 commit cdb2832

File tree

4 files changed

+18
-82
lines changed

4 files changed

+18
-82
lines changed

packages/cherry-markdown/build/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
// UMD 格式
2323
{
2424
...baseConfig.output,
25-
exports: 'named',
25+
exports: 'default',
2626
file: 'dist/cherry-markdown.js',
2727
format: 'umd',
2828
name: 'Cherry',
@@ -33,7 +33,7 @@ export default {
3333
// ESM 格式
3434
{
3535
...baseConfig.output,
36-
exports: 'named',
36+
exports: 'default',
3737
file: 'dist/cherry-markdown.esm.js',
3838
format: 'esm',
3939
name: 'Cherry',

packages/cherry-markdown/build/rollup.base.config.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -107,34 +107,6 @@ const options = {
107107
presets: babelConfig.presets,
108108
plugins: babelConfig.plugins,
109109
}),
110-
// TODO: 重构抽出为独立的插件
111-
{
112-
name: 'dist-types',
113-
generateBundle(options, bundle, isWrite) {
114-
const bundles = Object.keys(bundle);
115-
bundles.forEach((fileName) => {
116-
if (!fileName.endsWith('.js')) {
117-
return;
118-
}
119-
const file = bundle[fileName];
120-
const fileBaseName = fileName.replace(/\.js$/, '');
121-
const entryFileName = file.facadeModuleId.split(/[/\\]/).pop();
122-
const entryFileBase = entryFileName.replace(/\.js$/, '');
123-
const namedExports = file.exports.filter((name) => name !== 'default');
124-
const defaultName = options.name;
125-
const source = [
126-
`import ${defaultName}, { ${namedExports.join(', ')} } from "./types/${entryFileBase}";`,
127-
`export { ${namedExports.join(', ')} };`,
128-
`export default ${defaultName};`,
129-
].join('\n');
130-
this.emitFile({
131-
type: 'asset',
132-
fileName: `${fileBaseName}.d.ts`,
133-
source,
134-
});
135-
});
136-
},
137-
},
138110
],
139111
onwarn(warning, warn) {
140112
// 忽略 juice 的 circular dependency

packages/cherry-markdown/src/index.cherry.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

packages/cherry-markdown/src/index.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,22 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
export * from './index.core';
16+
import Cherry from './index.core';
17+
import MermaidCodeEngine from '@/addons/cherry-code-block-mermaid-plugin';
18+
import PlantUMLCodeEngine from '@/addons/cherry-code-block-plantuml-plugin';
19+
import EChartsTableEngine from '@/addons/advance/cherry-table-echarts-plugin';
20+
import mermaid from 'mermaid';
1721

18-
// 导出核心版
19-
export { default as core } from './index.core';
22+
const mermaidAPI = mermaid?.mermaidAPI;
2023

21-
// 导出引擎版
22-
export { default as engine } from './index.engine.core';
24+
// 初始化 mermaid 插件
25+
Cherry.usePlugin(MermaidCodeEngine, {
26+
mermaid,
27+
mermaidAPI,
28+
theme: 'default',
29+
sequence: { useMaxWidth: false },
30+
});
31+
Cherry.usePlugin(PlantUMLCodeEngine, {});
32+
Cherry.usePlugin(EChartsTableEngine);
2333

24-
// 导出流式渲染版
25-
export { default as stream } from './index.stream';
26-
27-
// 导出插件
28-
export { default as MermaidPlugin } from '@/addons/cherry-code-block-mermaid-plugin';
29-
export { default as PlantUMLPlugin } from '@/addons/cherry-code-block-plantuml-plugin';
30-
export { default as EChartsTablePlugin } from '@/addons/advance/cherry-table-echarts-plugin';
31-
export { default as TapdCheckListPlugin } from '@/addons/advance/cherry-tapd-checklist-plugin';
32-
export { default as TapdHtmlTagPlugin } from '@/addons/advance/cherry-tapd-html-tag-plugin';
33-
export { default as TapdTablePlugin } from '@/addons/advance/cherry-tapd-table-plugin';
34-
35-
// 默认导出使用带 mermaid 的版本
36-
export { default } from './index.cherry';
34+
export default Cherry;

0 commit comments

Comments
 (0)