readme.hbs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # {{ name }}
  2. This project was generated with [`@vendure/create`](https://github.com/vendurehq/vendure/tree/master/packages/create).
  3. Useful links:
  4. - [Vendure docs](https://www.vendure.io/docs)
  5. - [Vendure Discord community](https://www.vendure.io/community)
  6. - [Vendure on GitHub](https://github.com/vendurehq/vendure)
  7. - [Vendure plugin template](https://github.com/vendurehq/plugin-template)
  8. ## Directory structure
  9. * `/src` contains the source code of your Vendure server. All your custom code and plugins should reside here.
  10. * `/static` contains static (non-code) files such as assets (e.g. uploaded images) and email templates.
  11. ## Development
  12. ```
  13. npm run dev
  14. ```
  15. will start the Vendure server and [worker](https://www.vendure.io/docs/developer-guide/vendure-worker/) processes from
  16. the `src` directory.
  17. ## Build
  18. ```
  19. npm run build
  20. ```
  21. will compile the TypeScript sources into the `/dist` directory.
  22. ## Production
  23. For production, there are many possibilities which depend on your operational requirements as well as your production
  24. hosting environment.
  25. ### Running directly
  26. You can run the built files directly with the `start` script:
  27. ```
  28. npm run start
  29. ```
  30. You could also consider using a process manager like [pm2](https://pm2.keymetrics.io/) to run and manage
  31. the server & worker processes.
  32. ### Using Docker
  33. We've included a sample [Dockerfile](./Dockerfile) which you can build with the following command:
  34. ```
  35. docker build -t vendure .
  36. ```
  37. This builds an image and tags it with the name "vendure". We can then run it with:
  38. ```
  39. # Run the server
  40. docker run -dp 3000:3000 -e "DB_HOST=host.docker.internal" --name vendure-server vendure npm run start:server
  41. # Run the worker
  42. docker run -dp 3000:3000 -e "DB_HOST=host.docker.internal" --name vendure-worker vendure npm run start:worker
  43. ```
  44. Here is a breakdown of the command used above:
  45. - `docker run` - run the image we created with `docker build`
  46. - `-dp 3000:3000` - the `-d` flag means to run in "detached" mode, so it runs in the background and does not take
  47. control of your terminal. `-p 3000:3000` means to expose port 3000 of the container (which is what Vendure listens
  48. on by default) as port 3000 on your host machine.
  49. - `-e "DB_HOST=host.docker.internal"` - the `-e` option allows you to define environment variables. In this case we
  50. are setting the `DB_HOST` to point to a special DNS name that is created by Docker desktop which points to the IP of
  51. the host machine. Note that `host.docker.internal` only exists in a Docker Desktop environment and thus should only be
  52. used in development.
  53. - `--name vendure-server` - we give the container a human-readable name.
  54. - `vendure` - we are referencing the tag we set up during the build.
  55. - `npm run start:server` - this last part is the actual command that should be run inside the container.
  56. ### Docker Compose
  57. We've included a [docker-compose.yml](./docker-compose.yml) file which includes configuration for commonly-used
  58. services such as PostgreSQL, MySQL, MariaDB, Elasticsearch and Redis.
  59. To use Docker Compose, you will need to have Docker installed on your machine. Here are installation
  60. instructions for [Mac](https://docs.docker.com/desktop/install/mac-install/), [Windows](https://docs.docker.com/desktop/install/windows-install/),
  61. and [Linux](https://docs.docker.com/desktop/install/linux/).
  62. You can start the services with:
  63. ```shell
  64. docker-compose up <service>
  65. # examples:
  66. docker-compose up postgres_db
  67. docker-compose up redis
  68. ```
  69. ## Plugins
  70. In Vendure, your custom functionality will live in [plugins](https://www.vendure.io/docs/plugins/).
  71. These should be located in the `./src/plugins` directory.
  72. To create a new plugin run:
  73. ```
  74. npx vendure add
  75. ```
  76. and select `[Plugin] Create a new Vendure plugin`.
  77. ## Migrations
  78. [Migrations](https://www.vendure.io/docs/developer-guide/migrations/) allow safe updates to the database schema. Migrations
  79. will be required whenever you make changes to the `customFields` config or define new entities in a plugin.
  80. To generate a new migration, run:
  81. ```
  82. npx vendure migrate
  83. ```
  84. The generated migration file will be found in the `./src/migrations/` directory, and should be committed to source control.
  85. Next time you start the server, and outstanding migrations found in that directory will be run by the `runMigrations()`
  86. function in the [index.ts file](./src/index.ts).
  87. If, during initial development, you do not wish to manually generate a migration on each change to customFields etc, you
  88. can set `dbConnectionOptions.synchronize` to `true`. This will cause the database schema to get automatically updated
  89. on each start, removing the need for migration files. Note that this is **not** recommended once you have production
  90. data that you cannot lose.
  91. ---
  92. You can also run any pending migrations manually, without starting the server via the "vendure migrate" command.
  93. ---
  94. ## Troubleshooting
  95. ### Error: Could not load the "sharp" module using the \[OS\]-x\[Architecture\] runtime when running Vendure server.
  96. - Make sure your Node version is ^18.17.0 || ^20.3.0 || >=21.0.0 to support the Sharp library.
  97. - Make sure your package manager is up to date.
  98. - **Not recommended**: if none of the above helps to resolve the issue, install sharp specifying your machines OS and Architecture. For example: `pnpm install sharp --config.platform=linux --config.architecture=x64` or `npm install sharp --os linux --cpu x64`