PHP   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php – 使用Composer在生产时安装npm和bower软件包(即没有devDependencies)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的composer.json文件中,我在脚本部分中有以下内容
"post-install-cmd": [
        "PHP artisan clear-compiled","PHP artisan optimize","npm install","bower install"
    ]

当运行“composer install”时,这将导致npm和bower安装所有的依赖项,认情况下包括devDependencies.当涉及到生产部署(例如“composer install –no-dev”时,我想启动“npm install -production”和“bower install -production”)

据我所知,根据传递的标志,似乎没有办法更改指定为’post-install-command’的列表,或者是设置变量的方法,然后可以将其传递给post -install-CMD.

我错过了什么吗?使用COR_481_11845@poser似乎不可能只使用配置进行dev和production安装.我真的必须在制作时使用COR_481_11845@poser install –no-scripts,然后自己手动运行所有四个命令?这似乎有点笨拙.

您可以随时使用PHP对您进行环境检测,然后从同一脚本安装其他依赖项.这不是很好,很干净,比如在安装后的cmd中包括npm和bower,但是会让你找到你想要的东西.
"post-install-cmd": [
     "PHP artisan clear-compiled","PHP path/to/installer.PHP"
 ]

示例installer.PHP

// Logic to determine the environment. This Could be determined many ways,and depends on how your
// application's environment is determined. If you're making use of Laravel's environment
// capabilities,you Could do the following:
$env = trim(exec('PHP artisan env'));

// Clean up response to get the value we actually want
$env = substr($env,strrpos($env,' ') + 1);

$envFlag = ($env === 'production')
    ? '--production'
    : '';

// Install npm
passthru("npm install {$envFlag}");
// Install bower
passthru("bower install {$envFlag}");

您可以使这个例子更加健壮,甚至为它创建一个工匠指令.

大佬总结

以上是大佬教程为你收集整理的php – 使用Composer在生产时安装npm和bower软件包(即没有devDependencies)全部内容,希望文章能够帮你解决php – 使用Composer在生产时安装npm和bower软件包(即没有devDependencies)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。