在E2E测试过程中,我通过Vue CLI自动安装Vue3,确切的命令是:
npx --yes @vue/cli create vue3 --packageManager npm -n -i '{"useConfigFiles":true,"plugins":{"@vue/cli-plugin-babel":{},"@vue/cli-plugin-typescript":{"classComponent":false,"useTsWithBabel":true},"@vue/cli-plugin-pwa":{},"@vue/cli-plugin-router":{"historyMode":true},"@vue/cli-plugin-vuex":{},"@vue/cli-plugin-eslint":{"config":"prettier","lintOn":["save"]}},"vueVersion":"3"}'
问题是,在这个过程中,这个问题不断出现:
? Your connection to the default yarn registry seems to be slow.
Use https://registry.npmmirror.com for faster installation? (Y/n)
由于正在等待输入,因此构建失败。如何取消此提示?
我通过查看Vue CLI源代码找到了解决方案。如果您使用注册表参数运行 create 命令,或者可以设置环境变量 VUE_CLI_TEST 以避免出现该提示。由于我不知道设置该变量还有什么其他影响,因此我使用注册表命令运行。 这是来自 src 的代码,
shouldUseTaobao
是负责提示的函数:
const args = minimist(process.argv, {
alias: {
r: 'registry'
}
})
let registry
if (args.registry) {
registry = args.registry
} else if (!process.env.VUE_CLI_TEST && await shouldUseTaobao(this.bin)) {
registry = registries.taobao
} else {
try {
if (scope) {
registry = (await execa(this.bin, ['config', 'get', scope + ':registry'])).stdout
}
if (!registry || registry === 'undefined') {
registry = (await execa(this.bin, ['config', 'get', 'registry'])).stdout
}
} catch (e) {
// Yarn 2 uses `npmRegistryServer` instead of `registry`
registry = (await execa(this.bin, ['config', 'get', 'npmRegistryServer'])).stdout
}
}