NestJS视图未添加到Dist [英] NestJS Views Not gettings added to Dist

查看:485
本文介绍了NestJS视图未添加到Dist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件夹结构与下面类似.

My folder structure is similar to below.

public
views
src
  main.ts
  /users
       users.controller.ts
       /views
         my-view.hbs
  /books
       books.controller.ts
       /views
         my-view.hbs

这就是我用来添加模板和视图的方法

This is what i use to add the templates and views

 const app = await NestFactory.create<NestExpressApplication>(
    AppModule,
  );
  console.log(join(__dirname, 'public'));

  app.useStaticAssets(join(__dirname, '..', 'public'));
  app.setBaseViewsDir(join(__dirname, '..', 'views'));
  app.setViewEngine('hbs');
  hbs.registerPartials(join(__dirname, '..', 'views', 'partials'));

我的package.json脚本看起来像这样

My package.json scripts looks like this

"scripts": {
    "prebuild": "rimraf dist",
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "start": "nest start",
    "start:dev": "nest start --watch",
    "start:debug": "nest start --debug --watch",
    "start:prod": "node dist/src/main",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
    "test:e2e": "jest --config ./test/jest-e2e.json"
  },

我的问题是,当我在开发人员模式下运行nest时,它会构建分发代码,并且不会添加视图和公用文件夹.

My issue is that when i run nest in dev mode it builds the distribution code and it doesn't add the views and the public folder.

推荐答案

检查官方文档中的部分.

Check this section in the official documentation.

使用assetsnest build将分发非TypeScript文件,例如.graphql文件,图像,.html文件和其他资产,这是开发构建步骤的一部分.

With assets, nest build will distribute non-TypeScript files, such as .graphql files, images, .html files and other assets as part of your development build step.

示例:

"assets": ["**/*.hbs"]

将此添加到位于根目录的nest-cli.json文件中.

Add this to your nest-cli.json file located in the root directory.

这篇关于NestJS视图未添加到Dist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆