如何在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"
},
其他回答
将PORT环境变量添加到package.json中的服务脚本中:
"serve": "PORT=4767 vue-cli-service serve",
在webpack.config.js中:
module.exports = {
......
devServer: {
historyApiFallback: true,
port: 8081, // you can change the port there
noInfo: true,
overlay: true
},
......
}
您可以在模块中更改端口。exports -> devServer ->端口。
然后你重新启动npm run dev。你可以得到那个。
你应该擅长这个:
“serve”:“vue-cli-service service——port 8081”,
如果你想改变localhost端口,你可以改变package.json中的scripts标签:
"scripts": {
"serve": "vue-cli-service serve --port 3000",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
vue-cli版本3的另一种方法是在根项目目录中添加一个.env文件(与package.json一起),内容如下:
端口= 3000
运行npm run serve现在将指示应用程序在端口3000上运行。
推荐文章
- 如何在vue-cli项目中更改端口号
- Angular 2模板中的标签是什么意思?
- JavaScript .includes()方法的多个条件
- 窗口。亲近与自我。close不关闭Chrome中的窗口
- 同步和异步编程(在node.js中)的区别是什么?
- 在d3.js中调整窗口大小时调整svg的大小
- 如何编辑通过npm安装的节点模块?
- 如何将两个字符串相加,就好像它们是数字一样?
- 绑定多个事件到一个监听器(没有JQuery)?
- 在JavaScript中将JSON字符串解析为特定对象原型
- 将字符串“true”/“false”转换为布尔值
- 如何使用JavaScript代码获得浏览器宽度?
- event.preventDefault()函数在IE中无法工作
- indexOf()和search()的区别是什么?
- 错误:'types'只能在.ts文件中使用- Visual Studio Code使用@ts-check