New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scripting: Modules #1452
Scripting: Modules #1452
Conversation
100648c
to
d0af519
Compare
d4c6e9c
to
0aeba07
Compare
zh/scripting/language-support.md
Outdated
- [全局对象 globalThis](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/globalThis) | ||
- [可选链操作符 `?.`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) | ||
- [空值合并操作符 `??`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator) | ||
- [逻辑空赋值操作符 `??=`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_nullish_assignment)、[逻辑与赋值操作符 `&&=`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND_assignment)、[逻辑或赋值操作符 `||=`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议这里列一个标题
- 逻辑赋值操作符
- 逻辑空...
- 逻辑与...
- 逻辑或...
zh/scripting/modules/spec.md
Outdated
|
||
项目资源目录下,以 `.ts` 作为后缀的文件。例如 `assets/scripts/foo.ts`、`assets/scripts/bar.mjs`,都视为 ESM 格式。 | ||
|
||
对于任何其它模块,Cocos Creator 选择与 Node.js 类似的规则来[鉴别格式](https://nodejs.org/api/packages.html#packages_determining_module_system)。具体地,以下文件将被视为 ESM 格式: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文字和链接之间需要有空格
选择与 Node.js 类似的规则来 鉴别格式
zh/scripting/modules/spec.md
Outdated
|
||
### 后缀与目录导入 | ||
|
||
Cocos Creator 对模块说明符中模块的后缀要求更偏向于 Web:必须指定后缀并且不支持 Node.js 式的目录导入。然而,基于历史原因和现行的一些限制,TypeScript 模块不允许给出后缀并支持 Node.js 式的目录导入。具体来说: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为啥用 “:”
zh/scripting/modules/spec.md
Outdated
|
||
在 ESM 模块中,通过标准的导入导出语句与目标模块进行交互,例如: | ||
|
||
```js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“```ts” 吧
// [Module] { default: <module.exports> } | ||
``` | ||
|
||
<!-- TODO:guess named exports --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是漏了?通常内容间一个换行就够
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里专门注释的
zh/scripting/external-scripts.md
Outdated
@@ -1,6 +1,8 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
开头不需要留一个空行
zh/scripting/external-scripts.md
Outdated
@@ -1,6 +1,8 @@ | |||
|
|||
# 外部代码支持 | |||
|
|||
⚠️ 注意,从 3.0 开始,推荐使用模块代替插件脚本的使用! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> **注意**:从 Cocos Creator 3.0 开始,推荐使用模块代替插件脚本!
@@ -1,6 +1,8 @@ | |||
|
|||
# 外部代码支持 | |||
|
|||
⚠️ 注意,从 3.0 开始,推荐使用模块代替插件脚本的使用! | |||
|
|||
## 插件脚本 | |||
|
|||
当脚本资源在导入时设置了 **导入为插件**,此脚本资源便称为 **插件脚本**。插件脚本通常用于引入第三方库。目前仅支持 JavaScript 插件脚本。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.0 并没有 “导入为插件” 这个功能吧?
Cocos Creator 支持 TypeScript 4.1.0。在此基础上,做了以下限制: | ||
|
||
- `tsconfig.json` 不会被读取。每个项目都隐含着如下选项: | ||
```json5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码跟正文保留一个空行
zh/scripting/language-support.md
Outdated
"forceConsistentCasingInFileNames": true, | ||
}, | ||
} | ||
``` | ||
|
||
- 隐含着 `isolatedModules` 选项,这意味着: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是对代码的补充吧?那不需要另起一行了,前面保留两个空格的缩进就好了:
其中的 isolatedModules
表示:
zh/scripting/modules/spec.md
Outdated
|
||
CommonJS 模块的 [**ECMAScript 模块命名空间**](https://tc39.es/ecma262/#sec-module-namespace-objects) 表示,是含有一个 `default` 导出的命名空间,其中的 `default` 导出就指向 CommonJS 模块的 `module.exports` 的值。 | ||
|
||
该 [**模块命名空间外来对象**](https://tc39.es/ecma262/#module-namespace-exotic-object) 可以通过 `import * as m from 'cjs'` 来观测: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
该 [**模块命名空间外来对象**](https://tc39.es/ecma262/#module-namespace-exotic-object) 可以通过 `import * as m from 'cjs'` 来观测: | |
该 [模块命名空间外来对象](https://tc39.es/ecma262/#module-namespace-exotic-object) 可以通过 `import * as m from 'cjs'` 来观测(观察?): |
zh/scripting/modules/spec.md
Outdated
|
||
<!-- TODO:guess named exports --> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一个空行就够了,留这么多空行显示的也只是一个空行
|
||
### 解析算法规范 | ||
|
||
`CREATOR_ESM_RESOLVE(specifier, parentURL)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分都是英文的吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meicuo
> npm install -g nrm | ||
``` | ||
|
||
> `-g` 代表全局:直接安装到当前计算机中。因此,只要执行一次后续就无需再次执行。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> `-g` 代表全局:直接安装到当前计算机中。因此,只要执行一次后续就无需再次执行。 | |
> `-g` 表示全局,会将 NPM 包直接安装到当前计算机中,只要执行一次后续就不需要再次执行。 |
|
||
## 安装 NPM 包 | ||
|
||
在项目根目录下,执行 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在项目根目录下,执行 | |
在项目根目录中执行以下命令: |
另外,这几篇文档都没有加到 SUMMARY.md 中 |
index.md加了就行了吧 |
@@ -0,0 +1,36 @@ | |||
# 示例:导入游戏联机对战引擎 MGOBE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要用我们官方提供的 Service 做为示例。如果用这个做为示例的话,那大家自己接入就好了,就不会用 Cocos Service 了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已移除这个示例
|
||
``` | ||
📂 assets | ||
📂 Libs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大小写不一致啊,为什么不统一小写开头
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已移除这个示例
```ini | ||
# .gitignore 文件 | ||
|
||
node_modules/ # 忽略 node_modules 目录 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们新建项目默认的 .gitignore 里面已经有忽略 node_modules 了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已移除这段
@@ -0,0 +1,126 @@ | |||
# 示例:通过 NPM 使用 protobuf.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已更新
No description provided.