[英]How to install jQuery with Composer?
I have been able to install repositories that do not have a composer.json file like this: 我已经能够安装没有这样的composer.json文件的存储库:
{
"type": "package",
"package": {
"name": "yahoo/yui-compressor",
"version": "2.0.4",
"dist": {
"url": "http://yui.zenfs.com/releases/yuicompressor/yuicompressor-2.4.7.zip",
"type": "zip"
}
}
},
I took the "type": "zip" part from the docs, but I couldn't find many other types. 我从文档中选择了“type”:“zip”部分,但我找不到很多其他类型。 For example, I need to install jQuery, but I don't know what to put in type ("js" did not work). 例如,我需要安装jQuery,但我不知道要放入什么类型(“js”不起作用)。
{
"type": "package",
"package": {
"name": "jquery/jquery",
"version": "1.7.2",
"dist": {
"url": "http://code.jquery.com/jquery-1.7.2.js",
"type": "js"
}
}
}
Any ideas? 有任何想法吗?
EDIT : I'm adding the full solution to help @CMCDragonkai: 编辑 :我正在添加完整的解决方案来帮助@CMCDragonkai:
"require": {
"vendorname/somefile": "1.2.3",
},
"repositories": [
{
"type": "package",
"package": {
"name": "vendorname/somefile",
"version": "1.2.3",
"dist": {
"url": "http://example.com/somefile.txt",
"type": "file"
}
}
}
]
Actually there is an easier way to install jQuery, just type: 实际上有一种更简单的方法来安装jQuery,只需输入:
{
"require": {
"components/jquery": "1.9.*"
}
}
It uses Component Installer for Composer and by default all assets from Component are installed under components
, but it can be customize. 它使用Component Installer for Composer ,默认情况下,Component的所有资产都安装在components
下,但可以自定义。 ( see docs ). ( 见文档 )。
This is simply a missing feature. 这只是一个缺失的功能。 There should probably be a new type of dist which is just a single plaintext file to be downloaded and left as-is. 可能应该有一种新类型的dist,它只是一个要下载并保持原样的纯文本文件。 Please file a feature request on the github issue tracker: https://github.com/composer/composer/issues/ 请在github问题跟踪器上提交功能请求: https : //github.com/composer/composer/issues/
EDIT : 编辑:
The feature actually exists but wasn't documented. 该功能实际存在但未记录。
"type": "file"
As outlined already, part one of the solution is defining you own repositories and the "type: ": "file"
repository definition option. 如前所述,解决方案的第一部分是定义您自己的存储库和"type: ": "file"
存储库定义选项。 But a subsequent issue is getting composer to put the JQuery where you want it. 但随后的问题是让作曲家把JQuery放到你想要的地方。 As it stands, composer seems to be limited to downloading dependency source under vendor-dir
(which is annoying but probably related to autoloading requirements). 就目前而言,作曲家似乎仅限于在vendor-dir
下下载依赖源(这很烦人,但可能与自动加载要求有关)。 The general fix to this limitation is to write a composer plugin that overcomes it. 对此限制的一般修复是编写一个克服它的composer插件。 Seems to be a few plugins that can manage this. 似乎是一些可以管理它的插件。 The simplest most lightweight solution I've found is PHP Composer Asset Manager , which is dedicated to managing non PHP/Composer "assets". 我发现的最简单,最轻量级的解决方案是PHP Composer Asset Manager ,它专门用于管理非PHP / Composer“资产”。 Though, it has at least one limitation in that changes that the plugin makes are not managed/detected by composer. 但是,它至少有一个限制,即插件所做的更改不会被作曲家管理/检测到。 Still usable. 仍然可用。
Here's a full composer.json
to install JQuery using that plugin: 这是一个完整的composer.json
用于使用该插件安装JQuery:
{
"name": "foo/bar",
"require":
{
"phpclasses/assets": "*",
"jquery/jquery": "*"
},
"repositories": [
{
"type": "composer",
"url": "http://www.phpclasses.org/"
},
{
"type": "package",
"package": {
"name": "jquery/jquery",
"version": "1.7.2",
"type": "jquery",
"dist": {
"url": "http://code.jquery.com/jquery-1.7.2.js",
"type": "file"
}
}
}
],
"extra": {
"assets": {
"actions": [
{
"type": "copy",
"target": "webroot/js",
"pattern": "\\.js$"
}
],
"packages": {
"jquery/jquery": "*"
}
}
}
}
使用npm
, yarn
或WebPack
而不是Composer,它们可以更好地满足这种需求。
you can install jquery by using npm like so, 你可以像这样使用npm来安装jquery,
npm install jquery
https://www.npmjs.com/package/jquery https://www.npmjs.com/package/jquery
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.