想象一下:我有main.ts
和sw.ts
。
如何将main.ts
编译到js/
文件夹并将sw.ts
编译到root
目录?能给我一个例子吗?
答案 0 :(得分:1)
我在以下页面的帮助下找到了解决方案:Projects References。
对我有用的是为每个目录创建一个新的tsconfig.json
文件。之后,您应该在主要 tsconfig.json
中使用它:
"references": [
{ "path": "PATH/TO/EACH/OTHER/TSCONFIG.JSON/FILES" }
]
最重要的是,您还必须将此选项添加到每个次要文件 compilerOptions
文件的tsconfig.json
中:
"composite": true
此外,使用 "include"
指向特定.ts
将使用的每个tsconfig.json
文件:
"include": [
"./homeWork.ts",
"./myGame.ts"
]
或
"include": [
"./*.ts" //Points to every .ts file inside that directory.
]
现在,您应该能够使用与主tsconfig.json
相同目录中的任何这些命令一次编译所有文件:
tsc --build
; tsc -b //Alias for the above command
; tsc -w -b //Above command, including the option -w for watching changes recursively
。tsconfig.json
可能具有的每个引用; 答案 1 :(得分:0)
在单个编译中是不可能的。
您将必须使用不同的const initialState = { counter: 0 };
const myReducer = (state = initialState, action) => {
switch(action.type) {
case 'DO_SOMETHING':
return {
...state,
counter: state.counter + 1
};
case 'CLEAN_STATE':
return initialState;
}
}
文件或class MyComponent extends React.Component {
render () {
return (
<div>
<span>{this.props.counter}</span>
<button onClick={triggerActionThatCausesDO_SOMETHING} />
</div>
);
}
componentWillUnmount () {
triggerActionThatCausesCLEAN_STATE();
}
}
选项运行return getattr(commands, packet.capitalize())
两次。