问题描述
我根据 //www.yiiframework.com/doc-2.0/guide-start-installation.htmlrel =noreferrer>指南(安装Yii)。这没问题。根据指南,我还在全球范围内添加了 composer.phar。也没问题。
I have setup a basic app according to this guide (Installing Yii). This is no problem. According to the guide I have also added fxp/composer-asset-plugin globally to composer.phar. Also no problem.
现在我已经要求使用,作为托管*。但我不知道如何通过作曲家添加它。我知道我可以使用CDN代替,也可以手动下载和存储。但我更喜欢使用作曲家。那么我需要做些什么呢?
Now I've got the requirement to work with q.js which is hosted* as npm package. But I don't know how to add it via composer. I know I could probably use a CDN instead or download and store it manually. But I prefer using composer. So what do I have to do to make this work?
我已将它添加到我的composer.json中:
I have added this to my composer.json:
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": ">=2.0.4",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "*",
"npm-asset/q": "~1.4" <------
},
并调用 composer.phar update
但得到例外:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package npm-asset/q could not be found in any version,
there may be a typo in the package name.
这是一种错误的做法吗?
Is it a wrong approach?
我想知道如何将JS库添加到项目中。我只知道我必须稍后将其添加到资产中,但目前我无法获得JS文件。
I'd like to know in general how to add JS libraries to the project. I just know that I have to add it later to an Asset as well, but currently I'm not able to get the JS file in the first place.
*是托管了正确的术语?
* Is hosted the correct term?
推荐答案
目前在 composer.json中需要npm或bower包的最简单方法
是使用:
-
删除
fxp / composer-asset-plugin
:
composer global remove fxp/composer-asset-plugin
将存储库添加到 composer.json
:
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
然后你应该可以要求npm包使用 npm-asset /
前缀和bower包, bower-asset /
prefi x in composer.json
:
Then you should be able to require npm package with npm-asset/
prefix and bower package with bower-asset/
prefix in composer.json
:
"require": {
"bower-asset/bootstrap": "^3.3",
"npm-asset/jquery": "^2.2"
}
无需全局插件和更快的作曲家更新。
No need for global plugin and much faster composer updates.
这篇关于Yii2:如何通过composer添加JavaScript库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!