dingchenaobo / swc-demo

基于 swc + ts 的 node runtime 和 build 的一些简单尝试
0 stars 0 forks source link

构建方式 #1

Open dingchenaobo opened 2 years ago

dingchenaobo commented 2 years ago

目前是采用 glob 匹配走构建,这种构建方式很原始,可扩展性没有入口扫描高。

但是从入口扫描有个问题,node 项目不像 web 项目,读取一个模块只需要 import,node 读取模块的方式有 import、require、fs.[readFile | readFileSync | createReadStream | ...],总不能一个一个代理掉吧。

dingchenaobo commented 2 years ago

glob 模式构建的思路也比较简单: glob sync entrydir/*/ 就能匹配目标文件夹下的所有文件, 然后根据 extendnames 来确定那些文件是可以进行 compile 的,

dingchenaobo commented 2 years ago

同时这种模式还有一个问题,无法用 dist 目录直接运行项目,运行还是依赖了 node_modules 当然也没办法做 treessakeing、文件合并、split 之类的操作 但是直接依赖开发时的 node_modules 会安装 devDependencies,如果项目大起来,devDependencies 里面的东西可能会比较大,比如 mocha 之类的

dingchenaobo commented 2 years ago

同时这种模式还有一个问题,无法用 dist 目录直接运行项目,运行还是依赖了 node_modules 当然也没办法做 treessakeing、文件合并、split 之类的操作 但是直接依赖开发时的 node_modules 会安装 devDependencies,如果项目大起来,devDependencies 里面的东西可能会比较大,比如 mocha 之类的

docker 的分阶段构建或许是一个优化思路