NestJS Views Not gettings added to Dist

血红的双手。 提交于 2020-05-16 20:54:13

问题


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'));

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"
  },

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.


回答1:


Check this section in the official documentation.

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.

Example:

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

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



来源:https://stackoverflow.com/questions/60630960/nestjs-views-not-gettings-added-to-dist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!