Skip to content
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

perf: update build method #68

Merged
merged 6 commits into from
Jul 30, 2019
Merged

perf: update build method #68

merged 6 commits into from
Jul 30, 2019

Conversation

orzyyyy
Copy link
Collaborator

@orzyyyy orzyyyy commented Jul 20, 2019

No description provided.

@Yukimir
Copy link
Collaborator

Yukimir commented Jul 21, 2019

因为inject到页面里的脚本是用js写的而不是ts
所以这部分js代码用到的依赖库,还是得build的时候重新下一遍依赖

不过可以把这些只有ts代码用的依赖扔到dev-dep里去

@orzyyyy
Copy link
Collaborator Author

orzyyyy commented Jul 21, 2019

没明白要改啥,现在 build 不是正常吗。也就是说 electron 编译的时候读的仍然是 node_modules,这样的话依赖这么放着也没啥问题

说到底我就是不想在编译的时候再重新下一遍依赖,现在 build 正常,我没 get 到问题点

@orzyyyy
Copy link
Collaborator Author

orzyyyy commented Jul 21, 2019

顺带给个 collaborator 吧。涉及业务的我 request review 就是了

@Yukimir
Copy link
Collaborator

Yukimir commented Jul 22, 2019

因为有一部分代码是inject到页面里去的,那部分我用JS写的。有可能也要用到JS库,而这里调用是去找node_module的。
build并不会涉及这些js文件的依赖

@orzyyyy
Copy link
Collaborator Author

orzyyyy commented Jul 22, 2019

具体是指哪些 js?src/assets/js 下的文件还是哪的
主要是看这个 autoLogin 能正常工作就没在意这些了


好吧,总算是看明白了。我看看这玩意能不能改先

@Yukimir
Copy link
Collaborator

Yukimir commented Jul 22, 2019

其实你要是觉得测试的时候每次npm start都要下载依赖很蠢
你可以做软链接……
但是build的时候最好还是下载一下prod的依赖

@orzyyyy
Copy link
Collaborator Author

orzyyyy commented Jul 22, 2019

看了下,electron 里自带 node 方法,inject 打个包,然后全局引入 electron 应该就行了

还有就是插件怎么样才算是正常的,我这现在完全是黑箱操作

@Yukimir
Copy link
Collaborator

Yukimir commented Jul 22, 2019

我指的是request库之类的,还有一些解析你游资源的库。
proxyServer.ts里有用到这些
再就是未来可能inject部分的代码会用到第三方库(其实之前有,然后删掉了)

这么说吧,这个项目大概分成了三部分。
A部分 是Angular,也就是所谓的render进程使用的代码
B部分 是main.tsproxyServer.ts 这些,也就是所谓的main进程使用的代码
C部分 是src/assets/js/下的代码,也就是注入到webview中的代码
在打包的时候也是分别处理的。
插件我设计的是独立环境,所以可以不用管

A部分就是用的ng buildng build内置了webpack,会把所有依赖打包到一个叫vendor.js还是什么的文件里,输出到dist。因此这第一部分(render进程)是不依赖node_module的。
B部分只用了tsc来编译,并没有webpack。所以只是单纯的把ts文件转译成js文件。所以这部分是依赖于node_module
C分并没有编译,更没有打包,所以也是依赖于node_module

而publish时候是这样的
ng build把A部分编译打包到dist,同时C部分直接复制过去
然后tsc 把B部分编译到dist里。
最后用electron-builder把整个dist文件夹打包成asar,再配上electron runtime打包成安装程序

至于为什么npm start能跑起来
是因为node查找node_module
是会冒泡查找的
dist文件夹里没有,它就会往上一层目录找……
但是最终打包后在生产环境运行就不是这样了
所以package.json里会分devDependenciesdependencies两个部分
不带dev的那些就是上面说的B部分和C部分所使用的,而build:electron:main的时候跑的那个npm install --prod就是安装这些依赖,到时候打包成asar的时候可以带上他们。

最后说点题外话,electron实际上是内嵌了一个node环境。所以这里会有一个坑就是electron的node版本和你本地的node版本不同,导致一些native的包会出错的问题,因此有了electron-rebuild这个玩意(x


另外插件的文档我还没更新,之前大更过一次,一直在咕(
等我这边的一些事情处理完了会来弄……

@orzyyyy
Copy link
Collaborator Author

orzyyyy commented Jul 22, 2019

现在 B、C 部分都是直接编译到 es5 然后复制过去,然后生产环境少依赖
这样的话,要么就是依赖固定版本,也就是现在的做法;
要么就是打包多入口,这方法考虑吗?


当然我目前对 electron 的理解只有文档层面,如果这想法不行关了 pr 就是了。我到时候想想怎么改这玩意

@Yukimir
Copy link
Collaborator

Yukimir commented Jul 22, 2019

C部分是js,不编译的。因为是inject到页面里的,我个人觉得还是越原生越好
B部分是编译到es6的(x

然后你的需求的话其实很简单,只有publish的时候做npm install --prod就行了
开发环境下直接用父目录的node_module就行了(x

@Yukimir Yukimir merged commit 5fab61c into DogReactor:master Jul 30, 2019
@orzyyyy orzyyyy deleted the build branch July 30, 2019 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants