|
| 1 | +Drupal VM is configured to use [Drush make](drush-make.md) by default but supports building Drupal from a custom composer.json or creating a project from a composer package (`composer create-project`). |
| 2 | + |
| 3 | +## Using composer.json |
| 4 | + |
| 5 | +Add a `drupal.composer.json` next to your `config.yml` and switch the build system by setting `build_makefile: false` and `build_composer: true` in your `config.yml`. By default Drupal VM expects the Drupal code to be installed within a `docroot/` directory, if you use a different webroot directory, you need to adjust `drupal_core_path`. |
| 6 | + |
| 7 | +```yaml |
| 8 | +build_makefile: false |
| 9 | +build_composer: true |
| 10 | +``` |
| 11 | +
|
| 12 | +_The file set in `drupal_composer_path` (which defaults to `drupal.composer.json`) will be copied from your host computer into the VM's `drupal_composer_install_dir` and renamed `composer.json`. If you already have a composer.json within that directory, you can set `drupal_composer_path: false`._ |
| 13 | + |
| 14 | +## Using Composer when [Drupal VM is a composer dependency itself](../other/drupalv-composer-dependency.md) |
| 15 | + |
| 16 | +In the scenario where you already have an existing `composer.json` in the root of your project, follow the usual steps for installing with a composer.json but instead of creating a `drupal.composer.json` file, disable the transfering of the file by setting `drupal_composer_path` to `false`, and change `drupal_composer_install_dir` to point to the the directory where it will be located. If `drupal_composer_path` is not truthy, Drupal VM assumes it already exists. |
| 17 | + |
| 18 | +```yaml |
| 19 | +build_makefile: false |
| 20 | +build_composer: true |
| 21 | +drupal_composer_path: false |
| 22 | +drupal_composer_install_dir: "/var/www/drupalvm" |
| 23 | +``` |
| 24 | + |
| 25 | +## Creating a project from a composer package: `composer create-project` |
| 26 | + |
| 27 | +There's a couple of things you need to configure in your `config.yml`: |
| 28 | + |
| 29 | +- Switch the build system by setting `build_makefile: false`, `build_composer: false` and `build_composer_project: true`. |
| 30 | +- Configure the composer package in `drupal_composer_project_package`. |
| 31 | +- Additionally you can adjust the create-project CLI options in `drupal_composer_project_options` as well as add additional dependencies in `drupal_composer_dependencies`. |
| 32 | +- Ensure that the webroot configured in the composer package matches the one set in `drupal_core_path`. The default is `docroot/`. |
| 33 | + |
| 34 | +With [drupal-composer/drupal-project](https://github.com/drupal-composer/drupal-project) as an example your `config.yml` overrides would be: |
| 35 | + |
| 36 | +```yaml |
| 37 | +build_makefile: false |
| 38 | +build_composer: false |
| 39 | +build_composer_project: true |
| 40 | +
|
| 41 | +drupal_composer_project_package: "drupal-composer/drupal-project:8.x-dev" |
| 42 | +# Added `--no-dev` to avoid installing development dependencies. |
| 43 | +drupal_composer_project_options: "--prefer-dist --stability dev --no-interaction --no-dev" |
| 44 | +drupal_composer_dependencies: |
| 45 | + - "drupal/devel:8.*" |
| 46 | + |
| 47 | +drupal_core_path: "{{ drupal_composer_install_dir }}/web" |
| 48 | +``` |
| 49 | +
|
0 commit comments