Skip to content

Commit

Permalink
🐛 fix: 修正 reactCss 构建产物判断逻辑问题
Browse files Browse the repository at this point in the history
reactCSS 在生产环境下不产出 map 和 next,因此需要调整判断编译产物的逻辑
  • Loading branch information
arvinxx committed Jan 25, 2023
1 parent 70c2c74 commit a8288c2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
24 changes: 24 additions & 0 deletions src/utils/css.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { isReactCssResult } from './index';

describe('isReactCssResult', () => {
it('测试构建产物', () => {
const result = isReactCssResult({
name: '1mf3e6p',
styles:
'\n grid-area: footer;\n border-top: 1px solid rgba(5, 5, 5, 0.06);\n color: rgba(61, 62, 64, 0.45);\n font-size: 14px;\n line-height: 26px;\n text-align: center;\n padding: 24px 0;\n align-self: stretch;\n @media (max-width: 575px) {\n flex-direction: column;\n }\n ',
});
expect(result).toBeTruthy();
});

it('测试dev产物', () => {
const result = isReactCssResult({
name: '1mf3e6p',
map: undefined,
next: undefined,
styles:
'\n grid-area: footer;\n border-top: 1px solid rgba(5, 5, 5, 0.06);\n color: rgba(61, 62, 64, 0.45);\n font-size: 14px;\n line-height: 26px;\n text-align: center;\n padding: 24px 0;\n align-self: stretch;\n @media (max-width: 575px) {\n flex-direction: column;\n }\n ',
toString: () => {},
});
expect(result).toBeTruthy();
});
});
6 changes: 6 additions & 0 deletions src/utils/css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* 判断是否是 ReactCss 的编译产物
* @param params
*/
export const isReactCssResult = (params: any) =>
typeof params === 'object' && 'styles' in params && 'name' in params && 'toString' in params;
15 changes: 1 addition & 14 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
/**
* 判断是否是 ReactCss 的编译产物
* @param params
*/
export const isReactCssResult = (params: any) => {
return (
typeof params === 'object' &&
'styles' in params &&
'name' in params &&
'map' in params &&
'next' in params &&
'toString' in params
);
};
export * from './css';

0 comments on commit a8288c2

Please sign in to comment.