Search code examples
ember-cliyarnpkg

Configure ember-cli globally to use yarn for new projects


Is there any way to configure ember-cli globally to use yarn on new projects? A ember new <project-name> should use yarn without providing --yarn flag.

Background information

Recent versions of ember-cli uses yarn if

  • a yarn.lock file is present in projects root or
  • if --yarn flag is provided.

Since there can't be a yarn.lock before creating a new project, --yarn flag has to be used always on ember new <project-name> if yarn should be used.

If I got it correctly, ember-cli uses yam for configuration by a .ember-cli file. But as far as I know, this one is also only available in a existing project and could not set global configuration.

Motivation

I could of course always remember to use --yarn flag on creating a new project, but often I forget about it and have to abort the command. I prefer yarn also on init cause it's a lot faster. Also if it's not used already on project generation, yarn.lock file is not part of the initial commit. It's simply annoying.


Solution

  • .ember-cli can be configured both globally and on a per-package basis

    Global configuration is located in $HOME/.ember-cli

    Ember CLI’s runtime is configurable via a file named .ember-cli. The JSON-formatted file, which must be placed in your home directory, can include any command-line options whose names must be in camel case form

    Project only changes will be located in /path/to/project/.ember-cli.

    It is now also possible to override command line options by creating a file in your app’s root directory called .ember-cli and placing desired overrides in it.

    Since you're wanting to have all newly created projects to use yarn, add the following to $HOME/.ember-cli

    "yarn": true