-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# 批量转换 AMD 与 CommonJs 模块到 ES 模块 | ||
|
||
就前端而言,ES6 的模块化写法已经是主流了,但很多老的项目都是用 AMD 或者 CommonJs 规范写的。 | ||
由于 Webpack 现在已经慢慢不太支持 AMD 或者 CommonJs 规范的代码,所以需要把这两种规范的代码都转换成 ES6 规范的代码。 | ||
网上搜了一下,并没有这之类的工具,我就自己写了一个:[conv-mod](https://github.com/senntyou/conv-mod). | ||
|
||
## 安装 | ||
|
||
``` | ||
npm install conv-mod -g | ||
``` | ||
|
||
## 使用 | ||
|
||
``` | ||
conv-mod [options] <dir> [extraDirs...] | ||
``` | ||
|
||
## 参数 | ||
|
||
- `-f, --filter <filter>`: 查询某个字符串,过滤文件 | ||
- `-r, --regular`: 当查询某个字符串,过滤文件时,把查询字符串当作正则匹配 | ||
- `--amd`: 转化 AMD 模块 | ||
- `--cjs`: 转化 CommonJs 模块 | ||
|
||
## 示例 | ||
|
||
转换 `src` 目录下的 AMD 与 CommonJs 代码 | ||
|
||
``` | ||
conv-mod src --amd --cjs | ||
``` | ||
|
||
转换 `src/dir1,src/dir2` 目录下的 AMD 代码 | ||
|
||
``` | ||
conv-mod src/dir1 src/dir2 --amd | ||
``` | ||
|
||
## 后续 | ||
|
||
更多博客,查看 [https://github.com/senntyou/blogs](https://github.com/senntyou/blogs) | ||
|
||
作者:[深予之 (@senntyou)](https://github.com/senntyou) | ||
|
||
版权声明:自由转载-非商用-非衍生-保持署名([创意共享3.0许可证](https://creativecommons.org/licenses/by-nc-nd/3.0/deed.zh)) |