我可以将故事书目录移动到prjroot / build / storybook吗? (在React Native中)

时间:2018-10-13 08:49:50

标签: reactjs typescript react-native storybook

我正在将故事书介绍给我的React Native项目。

默认的故事书目录位于项目的根目录export default class FirstScreen extends Component { constructor(props){ super(props); this.state = { workType: "", workers: [] } } componentWillMount(){ fetch('http://192.168.1.6:3000/api/worker', { method:'GET', headers:{ Accept: 'application/json' } }) .then(response => response.json()) .then(responseData => this.setState({ workers:responseData }) ) } onPressYes = (workType) => { console.log(workType); } popUpDialog = (id, workType) => { this.setState ({ workType: workType }); this.popupDialog.show(); //make sure you set workType to "" when you click yes or no button in PopupDialog component so that it will work the next time you click on card } render() { const { workers, workType} = this.state; return ( <View style={{flex:1}}> <Header /> <ScrollView> {workers.map((a, index)=> ( <View style={{flex:1}}> <CardSection> <TouchableOpacity onPress={() => this.popUpDialog(a.id, a.work_type)}> <View style={{ maringTop: 10, marginLeft:120}}> <Image style={{ height: 100, width: 100 }} source={{ uri: a.work_type == 'Carpenter' ? images[0].image : images[1].image}}/> <Text style={{marginLeft:20, fontSize:20}}>{a.work_type}</Text> </View> </TouchableOpacity> </CardSection> </View> ))} <PopupDialog ref={popupDialog => { this.popupDialog = popupDialog; }} dialogStyle={{ backgroundColor: "#FFFFFF", height: 180, width:300, borderWidth:1,padding:10}} overlayBackgroundColor="#fff" dismissOnTouchOutside={true}> <View style={styles.dialogContentView}> <Text style={{fontSize:18, margingTop:10,color:"#000000"}}>Are you sure you want to submit?</Text> <View style={{flexDirection:'row'}}> <View style={styles.button_1}> <Button title="Yes" color="#FF6633" onPress={() => this.onPressYes(workType)}/> </View> <View style={styles.button_1}> <Button title="No" color="#FF6633" onPress={() =>this._onPressNo() }/> </View> </View> </View> </PopupDialog> </ScrollView> </View> ); } }

但是我想将其放置到<form> @csrf <button></button> </form> 中,因为我想用TypeScript编写故事书配置文件,然后将其构建到prjroot/storybook/中。

有什么方法可以使故事书识别已移动的路径?

1 个答案:

答案 0 :(得分:2)

通过将outDir选项添加到Typescript配置中。

tsconfig.json

{
  "compilerOptions": {
    "outDir": "build/",
    ...
  }
}

请注意,如果要指定源目录,则配置rootDirs也可能很有用。

https://storybook.js.org/configurations/typescript-config/#tsconfigjson

编辑:在特定情况下,必须使用react-native-storybook-loader进行配置:

"prestorybook": "rnstl --outputFile ./build/storybook/storyLoader.js --pattern \"**/*.story.tsx\" --searchDir ./App"
  • 具有新路径的outputFile
  • 扫描.tsx文件的模式
  • searchDir可用于忽略node_modules并防止冲突