Con*_*sea 6 javascript reactjs webpack babeljs styled-components
当尝试转换文件时,即使看似在其他文件中成功导入并使用(以相同的方式),也会Spacing.js
导致未定义的导入。styled-components
即使删除 styled-components babel 插件,也会出现类似的错误。
.babelrc
{
"presets": [["es2015", { "modules": false }], "react-native"],
"plugins": [
["styled-components", { "displayName": true }],
"react-hot-loader/babel",
"react-native-web",
"transform-decorators-legacy",
"transform-class-properties"
],
"env": {
"production": {
"plugins": [
"transform-react-inline-elements",
"transform-react-constant-elements"
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
Spacing.js
- 转译前的代码
import React, { Component, Node } from "React";
import styled from "styled-components";
type Props = {
size: string,
color: string,
fullWidth?: boolean
};
class SpacingComponent extends Component<Props> {
render(): Node {
const { size, color, fullWidth = false } = this.props;
return <Spacing size={size} color={color} fullWidth={fullWidth} />;
}
}
const Spacing = styled.View`
height: ${props => props.size}px;
background-color: ${props => props.color || "transparent"};
width: ${props => {
return props.fullwidth ? "100%" : props.size + "px";
}};
`;
export default SpacingComponent;
Run Code Online (Sandbox Code Playgroud)
styled-components
styled-components
库的代码 (v3.2.5)另一个例子是styled-components
从 babelrc 中删除 babel 插件,因此没有添加 withConfig 。
styled-components
babel 插件时生成错误babel 或 webpack 是否.default
在不需要时添加,如果是,我该如何调查原因?
归档时间: |
|
查看次数: |
8248 次 |
最近记录: |