nest new (项目名称 )在想要创建的文件夹中输入
创建完成后在命令行中 code (项目名称) 启动项目
进入项目后 package.json 配置文件中修改license为MIT
删除之前多余的文件后执行nest g module user 创建user文件夹
nest g controller user --no-spec 在user文件中创建controller文件
在main.ts中添加app.setGlobalPrefix('api/v1'); 相当于版本分割
添加api/v1后 之前的http://localhost:3000/user
变为http://localhost:3000/api/v1/user
在user中创建service nest g service user --no-spec
热重载
npm i --save-dev webpack-node-externals run-script-webpack-plugin webpack
热重载安装后需要创建配置文件webpack-hmr.config.js
const nodeExternals = require('webpack-node-externals');
const { RunScriptWebpackPlugin } = require('run-script-webpack-plugin');
module.exports = function (options, webpack) {
return {
...options,
entry: ['webpack/hot/poll?100', options.entry],
externals: [
nodeExternals({
allowlist: ['webpack/hot/poll?100'],
}),
],
plugins: [
...options.plugins,
new webpack.HotModuleReplacementPlugin(),
new webpack.WatchIgnorePlugin({
paths: [/\.js$/, /\.d\.ts$/],
}),
new RunScriptWebpackPlugin({ name: options.output.filename, autoRestart: false }),
],
};
};