Godot C# 项目在 VSCode 中的使用教程
1. 项目的目录结构及介绍
godot-csharp-vscode/
├── images/
├── src/
├── thirdparty/
├── typings/
├── .gitignore
├── .gitmodules
├── .vscodeignore
├── CHANGELOG.md
├── LICENSE
├── Makefile
├── README.md
├── format.sh
├── icon.png
├── package.json
├── tsconfig.json
├── tslint.json
├── webpack.config.js
- images/: 存放项目相关的图片资源。
- src/: 项目的源代码文件夹。
- thirdparty/: 第三方库文件夹。
- typings/: TypeScript 类型定义文件夹。
- .gitignore: Git 忽略文件配置。
- .gitmodules: Git 子模块配置。
- .vscodeignore: VSCode 忽略文件配置。
- CHANGELOG.md: 项目更新日志。
- LICENSE: 项目许可证。
- Makefile: 项目构建文件。
- README.md: 项目说明文档。
- format.sh: 格式化脚本。
- icon.png: 项目图标。
- package.json: 项目依赖和脚本配置。
- tsconfig.json: TypeScript 配置文件。
- tslint.json: TSLint 配置文件。
- webpack.config.js: Webpack 配置文件。
2. 项目的启动文件介绍
项目的启动文件主要是 package.json
中的 main
字段指定的入口文件。通常情况下,入口文件会定义项目的启动逻辑和依赖加载。
{
"main": "src/extension.js",
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "npm run compile && node ./node_modules/vscode/bin/test"
}
}
- main: 指定项目的入口文件为
src/extension.js
。 - scripts: 定义了一系列的脚本命令,用于编译、监视、安装和测试项目。
3. 项目的配置文件介绍
tsconfig.json
TypeScript 配置文件,定义了 TypeScript 编译选项。
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"sourceMap": true,
"strict": true,
"esModuleInterop": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
".vscode-test"
]
}
- compilerOptions: 编译选项,包括模块类型、目标 ECMAScript 版本、输出目录、源映射等。
- include: 包含的文件或目录。
- exclude: 排除的文件或目录。
tslint.json
TSLint 配置文件,定义了代码风格和规则。
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {
"no-console": false
},
"rulesDirectory": []
}
- defaultSeverity: 默认的严重级别。
- extends: 继承的规则集。
- jsRules: JavaScript 规则。
- rules: 自定义规则。
- rulesDirectory: 规则目录。
webpack.config.js
Webpack 配置文件,定义了模块打包的规则和选项。
const path = require('path');
module.exports = {
entry: './src/extension.js',
output: {
path: path.resolve(__dirname, 'out'),
filename: 'extension.js',
libraryTarget: 'commonjs2'
},
externals: {
vscode: 'commonjs vscode'
},