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: tech stack supports declare runtime plugin #2020

Merged
merged 1 commit into from
Jan 23, 2024
Merged
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
33 changes: 29 additions & 4 deletions src/features/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import path from 'path';
import { addAtomMeta, addExampleAssets } from '../assets';

export default (api: IApi) => {
const techStacks: IDumiTechStack[] = [];

api.describe({ key: 'dumi:compile' });

// register react tech stack by default
Expand Down Expand Up @@ -38,13 +40,36 @@ export default (api: IApi) => {
},
});

api.onGenerateFiles({
// make sure called before `addRuntimePlugin` key
// why not use `before: 'tmpFiles'`?
// because @umijs/preset-umi/.../tmpFiles has two `onGenerateFiles` key
// and `before` only insert before the last one
stage: -Infinity,
async fn() {
techStacks.push(
...(await api.applyPlugins({
key: 'registerTechStack',
type: api.ApplyPluginsType.add,
})),
);
},
});

// auto register runtime plugin for each tech stack
api.addRuntimePlugin(() =>
techStacks.reduce<string[]>((acc, techStack) => {
if (techStack.runtimeOpts?.pluginPath) {
acc.push(techStack.runtimeOpts.pluginPath);
}

return acc;
}, []),
);

// configure loader to compile markdown
api.chainWebpack(async (memo) => {
const babelInUmi = memo.module.rule('src').use('babel-loader').entries();
const techStacks: IDumiTechStack[] = await api.applyPlugins({
key: 'registerTechStack',
type: api.ApplyPluginsType.add,
});
const loaderPath = require.resolve('../../loaders/markdown');
const loaderBaseOpts: Partial<IMdLoaderOptions> = {
techStacks,
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export interface IDumiTechStackRuntimeOpts {
* path to runtime compile function module
*/
compilePath?: string;
/**
* path to runtime plugin for this tech stack
*/
pluginPath?: string;
}

export abstract class IDumiTechStack {
Expand Down
Loading