Skip to content

Commit

Permalink
fix: 修复按需引入失效
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrove committed Oct 15, 2024
1 parent 346ab17 commit 43556b6
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions esbuild.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,35 @@ const builder = async (type, entryPoints, outbase, outdir) => {
const assetPath = `${process.cwd()}/${asset}`;
fs.readFile(assetPath, 'utf8', (readErr, data) => {
if (readErr) console.error(`构建失败: ${readErr}`);
if (data?.indexOf('.less') > -1) {
const result = data?.replace('.less', '.css');
if (!data) return;
if (
data.indexOf('.less') > -1 ||
data.indexOf('import_react.default.forwardRef') > -1 ||
data.indexOf('React.forwardRef')
) {
/**
*
*/
const result = data
.replace('.less', '.css')
.replace(
/(import_react\.default\.memo|import_react\.default\.forwardRef|React\.forwardRef|React\.memo)/gm,
`/* @__PURE__ */ $1`,
);
fs.writeFile(assetPath, result, (writeErr) => {
if (writeErr) console.error(`构建失败: ${writeErr}`);
});
}
});

if (
asset.endsWith('.types.js') &&
assetPath.includes('es/')
) {
fs.writeFile(assetPath, 'export {};', (writeErr) => {
if (writeErr) console.error(`构建失败: ${writeErr}`);
});
}
}
});
});
Expand Down

0 comments on commit 43556b6

Please sign in to comment.