赞
踩
1.新建文件夹,使用vscode打开
2.在终端执行npm init
PS D:\ChromeCoreDownloads\vsc\demo> npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help init` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (demo) xiaoming_test_serve//取名字
接下来一直回车
3.安装 D:\ChromeCoreDownloads\vsc\demo> npm i express
新建主文件server.js
4.server.js编写完成后PS D:\ChromeCoreDownloads\vsc\demo> node server
5.新建static文件放入打包好的文件
6.http://localhost:5005/运行即可
7.解决mode:‘history’,刷新问题,在服务器中安装npm i connect-history-api-fallback,在server.js中引用
const express = require('express')
const history = require('connect-history-api-fallback');
const app = express()
app.use(history())
app.use(express.static(__dirname+'/static'))
在使用静态资源前引用
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。