midwayjs / midway

🍔 A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade. Works on AWS, Alibaba Cloud, Tencent Cloud and traditional VM/Container. Super easy integrate with React and Vue. 🌈
https://www.midwayjs.org/
MIT License
7.4k stars 577 forks source link

[Question]遇到Fun detected that your function sizes exceed 50M 该怎么处理 #1109

Open xmsz opened 3 years ago

xmsz commented 3 years ago

package.json

  "dependencies": {
    "@midwayjs/bootstrap": "^2.3.0",
    "@midwayjs/core": "^2.3.0",
    "@midwayjs/decorator": "^2.3.0",
    "@midwayjs/orm": "^1.3.1",
    "@midwayjs/web": "^2.3.0",
    "axios": "^0.21.1",
    "dayjs": "^1.10.5",
    "egg": "^2.0.0",
    "egg-scripts": "^2.10.0",
    "mysql2": "^2.2.5",
    "typeorm": "^0.2.34"
  },
  "devDependencies": {
    "@midwayjs/cli": "^1.2.73",
    "@midwayjs/egg-ts-helper": "^1.0.1",
    "@midwayjs/luckyeye": "^1.0.0",
    "@midwayjs/mock": "^2.3.0",
    "@types/jest": "^26.0.10",
    "@types/node": "^15.12.4",
    "cross-env": "^7.0.3",
    "jest": "^27.0.5",
    "mwts": "^1.0.5",
    "ts-jest": "^27.0.3",
    "typescript": "^4.0.0"
  },

执行npm run deploy

报错

Fun detected that your function  sizes exceed 50M.
? Use OSS bucket/object  as a function code, the codeSizeLimit can be expanded to 100M.Yo
u can deploy function with command "fun package && fun deploy" Yes
Executing command 'fun package && fun deploy'...

相关问题:https://github.com/midwayjs/midway/issues/764

czy88840616 commented 3 years ago

https://www.yuque.com/midwayjs/midway_v2/deploy_aliyun_faq#sJA7S

echosoar commented 3 years ago

如果还是包超大小,可以尝试使用试验性功能删除无用文件,f.yml中添加如下配置:

experimentalFeatures:
    removeUselessFiles: true
xmsz commented 3 years ago

https://www.yuque.com/midwayjs/midway_v2/deploy_aliyun_faq#sJA7S

删除package.json无效

xmsz commented 3 years ago

如果还是包超大小,可以尝试使用试验性功能删除无用文件,f.yml中添加如下配置:

experimentalFeatures:
    removeUselessFiles: true

有效

 - Experimental Feature RemoveUselessFiles
  - Useless files Count 5422
  - Remove Useless file 33.93 MB

这是为什么

不过现在也快50m了

        The function app_index has been packaged. A total of 9235 files were compressed and the final size was 41.77 MB
echosoar commented 3 years ago

可以到.serverless目录里面的node_modules按照大小排序看下是哪个包导致的:

du -hs * | sort -h
xmsz commented 3 years ago

可以到.serverless目录里面的node_modules按照大小排序看下是哪个包导致的:

du -hs * | sort -h

3.8M    @serverless-devs
4.1M    es-abstract
4.1M    eslint
4.5M    jsdom
4.9M    lodash
5.1M    moment
5.8M    node-notifier
6.2M    @babel
6.4M    @jest
6.5M    protobufjs
7.0M    figlet
7.4M    core-js
7.8M    @typescript-eslint
 17M    rxjs
 19M    inquirer
 19M    prettier
 25M    typeorm
 53M    detective-typescript
 58M    typescript
 67M    @midwayjs
 86M    @alicloud

然后我又检查了一遍依赖发现比原始项目多了

    "@midwayjs/cli-plugin-faas": "^1.2.73",
    "@midwayjs/fcli-plugin-fc": "^1.2.73",

而且是在dependencies的

然后我把这两个放在devDependencies里,就

3.7M    @serverless-devs
3.9M    jsdom
4.1M    es-abstract
4.6M    eslint
4.9M    lodash
5.1M    moment
5.8M    node-notifier
6.2M    @babel
6.5M    protobufjs
7.0M    figlet
7.1M    @typescript-eslint
7.4M    core-js
 17M    rxjs
 19M    prettier
 26M    typeorm
 53M    detective-typescript
 58M    typescript
 71M    @midwayjs
108M    @alicloud

虽然@alicloud和@midwayjs还是很大,但是最终上传变成了11m

 - Experimental Feature RemoveUselessFiles
  - Useless files Count 4519
  - Remove Useless file 21.65 MB

        The function app_index has been packaged. A total of 7040 files were compressed and the final size was 11.65MB
liSong5713 commented 3 years ago

是否考虑下增量打包呢?官方一个小demo 每次npm run deploy 都需要 1-3分钟

czy88840616 commented 3 years ago

部署无法增量。。。

waitingsong commented 3 years ago

怎么会有 58M typescript