有没有办法删除 "node_modules" 除了一个包(mocha)?
Is there a way to delete "node_modules" except for one package (mocha)?
我想在 Heroku 上部署我的应用程序后删除 node_modules
文件夹,同时我希望我的单元测试能够正常工作。
我尝试在 package.json
中的 heroku-postbuild
脚本中添加 node_modules
的删除。它工作正常,但后来我的 "test"
脚本失败了,因为他们没有找到 mocha
模块。
据我所知,这些脚本 运行 是并行的,因此将删除 node_modules
放在 "test"
脚本中也不起作用。您对此问题有任何解决方法吗?
"heroku-postbuild": "npm run build && del-cli ./node_modules/* ",
"test": "mocha -r source-map-support/register ./dist/tests.js"
更多信息:
我想删除它,因为它太大了。每次部署后我都会收到一条 Heroku 警告,提示已超过 slug 大小。该文件夹占用的空间超过 200MB。部署后我不需要 node_modules
因为我的应用程序是使用 Webpack 捆绑的。我唯一的问题是当 运行 进行我的单元测试时,我需要 node_modules
的唯一包是 mocha
.
I want to delete it because its size. I have a Heroku warning after every deploy that says that the slug size has exceeded. The folder is taking more than 200MB. And I don't need the node_modules
after I deploy because my app is bundled using Webpack. My only problem is when running my unit tests, the only package I need from node_modules/
is mocha
.
在这种情况下,您的大部分依赖项实际上并不是 dependencies
,而是 devDependencies
。
如果您将 mocha
保留在您的 dependencies
中并将其他所有内容移至 devDependencies
,您应该不需要做任何特别的事情。 Heroku prunes devDependencies
by default after building your slug.
我想在 Heroku 上部署我的应用程序后删除 node_modules
文件夹,同时我希望我的单元测试能够正常工作。
我尝试在 package.json
中的 heroku-postbuild
脚本中添加 node_modules
的删除。它工作正常,但后来我的 "test"
脚本失败了,因为他们没有找到 mocha
模块。
据我所知,这些脚本 运行 是并行的,因此将删除 node_modules
放在 "test"
脚本中也不起作用。您对此问题有任何解决方法吗?
"heroku-postbuild": "npm run build && del-cli ./node_modules/* ",
"test": "mocha -r source-map-support/register ./dist/tests.js"
更多信息:
我想删除它,因为它太大了。每次部署后我都会收到一条 Heroku 警告,提示已超过 slug 大小。该文件夹占用的空间超过 200MB。部署后我不需要 node_modules
因为我的应用程序是使用 Webpack 捆绑的。我唯一的问题是当 运行 进行我的单元测试时,我需要 node_modules
的唯一包是 mocha
.
I want to delete it because its size. I have a Heroku warning after every deploy that says that the slug size has exceeded. The folder is taking more than 200MB. And I don't need the
node_modules
after I deploy because my app is bundled using Webpack. My only problem is when running my unit tests, the only package I need fromnode_modules/
ismocha
.
在这种情况下,您的大部分依赖项实际上并不是 dependencies
,而是 devDependencies
。
如果您将 mocha
保留在您的 dependencies
中并将其他所有内容移至 devDependencies
,您应该不需要做任何特别的事情。 Heroku prunes devDependencies
by default after building your slug.