Skip to content

Commit

Permalink
refactor(play): 让play可以在ESM下编译 (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
otakustay committed Jan 29, 2022
1 parent 3ace896 commit 41e36cf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
9 changes: 9 additions & 0 deletions packages/cli-play/src/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ export const createWebpackConfig = async (target: string, cmd: PlayCommandLineAr
...(baseConfig.module?.rules ?? []),
],
},
resolve: {
...baseConfig.resolve,
fallback: {
...baseConfig.resolve?.fallback,
// React要从`17.0.3`开始才会有`exports`配置,这之前的版本在ESM下是必须加`.js`后续的。
// 利用这个`resolve.fallback`,可以在找不到`react/jsx-runtime`时跳到`react/jsx-runtime.js`上去,兼容旧版本。
'react/jsx-runtime': 'react/jsx-runtime.js',
},
},
};
return config;
};
2 changes: 0 additions & 2 deletions packages/cli-play/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
// TODO: 这里要改回`react-jsx`
"jsx": "preserve"
},
"include": ["src"],
"exclude": ["**/__tests__"]
Expand Down
5 changes: 4 additions & 1 deletion packages/cli-play/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"jsx": "preserve"
"jsx": "react-jsx",
"paths": {
"react/jsx-runtime": ["node_modules/@types/react/jsx-runtime.d.ts"]
}
},
"exclude": ["dist"]
}
2 changes: 0 additions & 2 deletions packages/config-babel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import getParseOnlyBabelConfigFilled from './parseOnly.js';
import getTransformBabelConfigFilled from './transform.js';
import {BabelConfigOptions, BabelConfigOptionsFilled} from './interface.js';

// TODO: 看看能不能为jest和eslint定制一个完全不依赖自己的babel plugin的配置出来

export type {BabelConfigOptions};

export const getParseOnlyBabelConfig = (options?: BabelConfigOptions): TransformOptions => {
Expand Down

0 comments on commit 41e36cf

Please sign in to comment.