PHP Composer: No Dev Mode that Sticks

前端 未结 2 1749
暖寄归人
暖寄归人 2021-01-07 18:52

When you install or update a project with composer, you can tell it to skip the development related dependencies (tests, build tools, etc.) with th

2条回答
  •  抹茶落季
    2021-01-07 19:36

    This was really annoying, so I finally wrote a simple bash script which asks about environment and run correct command:

    #! /bin/bash
    
    read -p "Which environment use to deploy: (P)roduction (T)est (D)ev? (p/t/d): " -n 1 -r
    echo
    
    if [[ $REPLY =~ ^[^PpTtDd]$ ]]; then
        echo "Incorrect environment";
        exit 1;
    fi
    
    # tasks to run before composer install (svn up/git pull)
    
    if [[ $REPLY =~ ^[Pp]$ ]]; then
        composer install --prefer-dist --no-dev --classmap-authoritative
    elif [[ $REPLY =~ ^[Tt]$ ]]; then
        composer install --prefer-dist --classmap-authoritative
    elif [[ $REPLY =~ ^[Dd]$ ]]; then
        composer install
    fi
    
    # additional tasks after composer install (clear cache, migrations, etc.)
    

    Saved it in bin/deploy in project and added execute permissions. So now I'm using bin/deploy instead of composer install:

    I also put other common tasks there (pull changes from VCS, clear cache, run migrations, etc.), so I have even less things to do and remember during deployment :).

提交回复
热议问题