纱线只安装一个包列表(即不是所有项目依赖项)
Yarn install a only a list of packages (ie not all the project dependencies)
我正在尝试在我的 CI 服务器的项目中启动一个脚本(github 操作)。由于安装我所有的依赖项需要很多时间,所以我只想安装我的依赖项的一个子集。
我尝试了以下方法:
# Bad solution1
yarn install # is not good for me because it install every dependencies = takes time
# Bad solution2
yarn add dependency1 dependency2 # idem
# Poor solution3
rm package.json yarn.lock
yarn add dependency1 dependency2 # would work but I have no garantie of keeping the same versions
有没有办法用纱线做到这一点?
我过去通过使用 rollup 捆绑脚本及其依赖项ci 并将文件提交到 repo 来解决这个问题。
然后您可以 运行 ci 上的脚本,而无需使用 node 或 yarn 安装。
这是一个示例 rollup.config.js 文件。它用于打字稿,但如果您使用的是 js,则应该能够将类似的东西放在一起。您必须安装汇总以及插件。
rollup.config.js
import typescript from "rollup-plugin-typescript2";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
module.exports = {
input: "src/my-script.ts",
output: {
file: "lib/my-script.js",
format: "cjs"
},
plugins: [
typescript({
typescript: require("typescript"),
module: "CommonJS"
}),
resolve(),
commonjs({ extensions: [".js", ".ts"] })
]
};
将脚本添加到您的 package.json 和 运行 yarn build
:
package.json
...
"scripts": {
"build": "rollup -c"
},
...
我正在尝试在我的 CI 服务器的项目中启动一个脚本(github 操作)。由于安装我所有的依赖项需要很多时间,所以我只想安装我的依赖项的一个子集。
我尝试了以下方法:
# Bad solution1
yarn install # is not good for me because it install every dependencies = takes time
# Bad solution2
yarn add dependency1 dependency2 # idem
# Poor solution3
rm package.json yarn.lock
yarn add dependency1 dependency2 # would work but I have no garantie of keeping the same versions
有没有办法用纱线做到这一点?
我过去通过使用 rollup 捆绑脚本及其依赖项ci 并将文件提交到 repo 来解决这个问题。
然后您可以 运行 ci 上的脚本,而无需使用 node 或 yarn 安装。
这是一个示例 rollup.config.js 文件。它用于打字稿,但如果您使用的是 js,则应该能够将类似的东西放在一起。您必须安装汇总以及插件。
rollup.config.js
import typescript from "rollup-plugin-typescript2";
import resolve from "rollup-plugin-node-resolve";
import commonjs from "rollup-plugin-commonjs";
module.exports = {
input: "src/my-script.ts",
output: {
file: "lib/my-script.js",
format: "cjs"
},
plugins: [
typescript({
typescript: require("typescript"),
module: "CommonJS"
}),
resolve(),
commonjs({ extensions: [".js", ".ts"] })
]
};
将脚本添加到您的 package.json 和 运行 yarn build
:
package.json
...
"scripts": {
"build": "rollup -c"
},
...