如何在Vue-cli项目中更改端口号,使其在另一个端口上运行而不是8080。
当前回答
最好的方法是更新包中的serve脚本命令。json文件。只需像这样追加——port 3000:
"scripts": {
"serve": "vue-cli-service serve --port 3000",
"build": "vue-cli-service build",
"inspect": "vue-cli-service inspect",
"lint": "vue-cli-service lint"
},
其他回答
最好的方法是更新包中的serve脚本命令。json文件。只需像这样追加——port 3000:
"scripts": {
"serve": "vue-cli-service serve --port 3000",
"build": "vue-cli-service build",
"inspect": "vue-cli-service inspect",
"lint": "vue-cli-service lint"
},
如果您正在使用vue cli 3,另一个选择是使用配置文件。创建vue.config.js与你的包在同一级别。Json,并像这样放置配置:
module.exports = {
devServer: {
port: 3000
}
}
使用脚本配置:
npm run serve --port 3000
工作很好,但如果你有更多的配置选项,我喜欢在配置文件中做。你可以在文档中找到更多信息。
如果你想临时改变端口号,你可以在npm run serve命令中添加一个-port选项。
运行服务-- --端口6058
进入“node_modules/@vue/cli-service/lib/options.js”目录 在“devServer”的底部,解锁代码 现在在“port”中给出你想要的端口号:)
devServer: {
open: process.platform === 'darwin',
host: '0.0.0.0',
port: 3000, // default port 8080
https: false,
hotOnly: false,
proxy: null, // string | Object
before: app => {}
}
我的天啊!这并不复杂,这些答案也同样有效。然而,这个问题的其他答案也很有效。
如果你真的想使用vue-cli-service,如果你想在你的包中有端口设置。你的'vue create <app-name>'命令基本上创建的Json文件,你可以使用以下配置:所以你脚本的整个配置是这样的:
...
"scripts": {
"serve": "vue-cli-service serve --port 3000",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
...
我在macOS设备上使用@vue/cli 4.3.1 (vue——version)。
我还添加了vue-cli-service引用: https://cli.vuejs.org/guide/cli-service.html