Skip to content

Commit

Permalink
fix(react-vite): modifyVite check env condition
Browse files Browse the repository at this point in the history
  • Loading branch information
innocces committed Jul 25, 2024
1 parent da265b6 commit 09ced6f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/taro-plugin-react-vite/project.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
"tabIndent": "insertSpaces",
"tabSize": 2
}
}
}
8 changes: 3 additions & 5 deletions examples/taro-plugin-react-vite/project.private.config.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"projectname": "taro-hooks-plugin-vite",
"setting": {
"compileHotReLoad": false,
"compileHotReLoad": true,
"urlCheck": false,
"bigPackageSizeSupport": true
},
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"condition": {
"miniprogram": {}
}
}
"condition": {}
}
23 changes: 10 additions & 13 deletions packages/plugin-react/src/runtime/modifyViteConfig.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import { IPluginContext } from '@tarojs/service';
import { chalk } from '@tarojs/helper';
import { reactLike } from './constant';
import { getRealRuntimePath, isVersion4, getDefine } from './shared';
import { getRealRuntimePath, getDefine } from './shared';

export function modifyViteConfig(ctx: IPluginContext) {
const { framework } = ctx.initialConfig;
ctx.modifyViteConfig?.(({ viteConfig }) => {
const taroHooksVitePlugins = [setDefinePlugin(), setAlias(framework)];
console.log(
chalk.blue(
`✨ 逮到一个使用taro-hooks的小可爱~ \n 当前使用的框架是: ${framework}`,
),
);

if (isVersion4() && 'modifyViteConfig' in ctx) {
ctx.modifyViteConfig(({ viteConfig }) => {
const taroHooksVitePlugins = [setDefinePlugin(), setAlias(framework)];
console.log(
chalk.blue(
`✨ 逮到一个使用taro-hooks的小可爱~ \n 当前使用的框架是: ${framework}`,
),
);

viteConfig.plugins.push(...taroHooksVitePlugins);
});
}
viteConfig.plugins.push(...taroHooksVitePlugins);
});
}

function setDefinePlugin() {
Expand Down

0 comments on commit 09ced6f

Please sign in to comment.