You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.md 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. Basic Usage
  2. ===========
  3. 1. [Installation](index.md)
  4. 2. [Composer Schema of Asset](schema.md)
  5. 3. [FAQs](faqs.md)
  6. ## Installation
  7. See the [Release Notes](https://github.com/francoispluchino/composer-asset-plugin/releases)
  8. to know the Composer version required.
  9. ### Global scope (per user) installation
  10. ```shell
  11. $ composer global require "fxp/composer-asset-plugin:~1.0"
  12. ```
  13. ### Project scope installation
  14. ```shell
  15. $ composer require "fxp/composer-asset-plugin:~1.0"
  16. ```
  17. ## Usage
  18. ### Usage with asset repository
  19. Adding a dependency on an asset, you must add the asset to the property
  20. `require` of the `composer.json` of your project.
  21. It must be prefixed with `{asset-type}-asset/`.
  22. **Example for twitter bootstrap:**
  23. ```json
  24. {
  25. "require": {
  26. "npm-asset/bootstrap": "dev-master"
  27. }
  28. }
  29. ```
  30. **or:**
  31. ```json
  32. {
  33. "require": {
  34. "bower-asset/bootstrap": "dev-master"
  35. }
  36. }
  37. ```
  38. ### Usage with VCS repository
  39. If your asset is not listed on the NPM- or Bower-Repository, or it is a private package, you can
  40. create a VCS repository for it. The repository must have an asset package file for NPM (`package.json`)
  41. or Bower (`bower.json`).
  42. In addition, the repository must respect the specifications of [Bower Spec]
  43. (https://github.com/bower/bower.json-spec) or [NPM Spec](https://docs.npmjs.com/files/package.json)
  44. for the package files. Concerning the version numbers and the tags, they must respect the [Semver 2.0]
  45. (http://semver.org/) format.
  46. If your repository does not contain a tag that repsent the number, you must put the flag `@dev` or directly
  47. use the development branch `dev-master`.
  48. **Example:**
  49. Add the following to your `composer.json`:
  50. ```json
  51. {
  52. "extra": {
  53. "asset-repositories": [
  54. {
  55. "type": "bower-vcs",
  56. "url": "https://github.com/vendor/exemple-asset-name.git"
  57. }
  58. ]
  59. }
  60. }
  61. ```
  62. **Availables drivers:**
  63. | Drivers | NPM | Bower |
  64. |---------------------|---------------------|-----------------------|
  65. | **auto** | `npm-vcs` | `bower-vcs` |
  66. | Git | `npm-git` | `bower-git` |
  67. | GitHub | `npm-github` | `bower-github` |
  68. | Git Bitbucket | `npm-git-bitbucket` | `bower-git-bitbucket` |
  69. | Mercurial | `npm-hg` | `bower-hg` |
  70. | Mercurial Bitbucket | `npm-hg-bitbucket` | `bower-hg-bitbucket` |
  71. | SVN | `npm-svn` | `bower-svn` |
  72. | Perforce | `npm-perforce` | `bower-perforce` |
  73. ### Overriding the config of a VCS Repository
  74. If you must use a repository other than that indicated by the registry of NPM or Bower,
  75. you must specify the name of the package with the asset prefix in the config of the VCS
  76. Repository.
  77. **Example:**
  78. ```json
  79. {
  80. "extra": {
  81. "asset-repositories": [
  82. {
  83. "type": "bower-vcs",
  84. "url": "https://github.com/vendor/exemple-asset-name.git",
  85. "name": "bower-asset/exemple-asset-name"
  86. }
  87. ]
  88. }
  89. }
  90. ```
  91. You can also use the standard format of Composer for naming your VCS Repository:
  92. ```json
  93. {
  94. "extra": {
  95. "asset-repositories": {
  96. "bower-asset/exemple-asset-name": {
  97. "type": "bower-vcs",
  98. "url": "https://github.com/vendor/exemple-asset-name.git"
  99. }
  100. }
  101. }
  102. }
  103. ```
  104. ### Usage with multiple versions of the same dependency
  105. If you need to use multiple versions of the same asset, you can do this by
  106. simply adding a version number after the package name, separated with the "-"
  107. character.
  108. **Example with Jquery:**
  109. ```json
  110. {
  111. "require": {
  112. "bower-asset/jquery": "1.11.*",
  113. "bower-asset/jquery-2.0.x": "2.0.x",
  114. "bower-asset/jquery-2.1.0": "2.1.0"
  115. }
  116. }
  117. ```
  118. The dependencies will then be placed in the following directories:
  119. - `vendor/bower-asset/jquery` for `1.11.*`
  120. - `vendor/bower-asset/jquery-2.0.x` for `2.0.x`
  121. - `vendor/bower-asset/jquery-2.1.0` for `2.1.0`
  122. ### Reduce the number of requests for getting the package definitions
  123. The root Composer package has a feature: all asset dependencies added will have automatically
  124. a filter applied, before the importation of the branches and the tags.
  125. In this way, all versions are not accepted by the constraint of version and they will be
  126. skipped to the importation, and will not be injected in the `Pool`. Of course, all constraints
  127. of versions are functional (exact version, range, wildcard, tilde operator).
  128. **For example:**
  129. The root `composer.json`:
  130. ```json
  131. {
  132. "minimum-stability": "dev",
  133. "require": {
  134. "npm-asset/example-asset1": ">=1.0@stable",
  135. "npm-asset/example-asset2": ">=2.3@RC",
  136. "npm-asset/example-asset3": ">=1.3@beta",
  137. "npm-asset/example-asset4": "~0.9@alpha",
  138. "npm-asset/example-asset4": "2.1.*",
  139. }
  140. }
  141. ```
  142. In case you have an dependency that that requires a sub asset dependency, and given that this
  143. optimization cannot be performed with the sub dependencies, you can add this asset dependency
  144. directly to the root Composer package, in the same way that if you wanted to use a
  145. well-defined version of this dependency.
  146. ### Disable the import filter using the installed packages
  147. By default, and for dramatically optimize performance for the `update`, the plugin filters the
  148. imports of definitions packages. In addition to filter with the dependencies in the root
  149. Composer package, the plugin filters the imports of packages definitions with the previous
  150. versions of the packages installed.
  151. However it may happen that Composer throws an exception, indicating that it can not find a
  152. compatible version. This happens if a dependency uses a new version lower than the installed
  153. version.
  154. Of course, several solutions can work around the problem (see the [FAQs]
  155. (faqs.md#composer-throws-an-exception-stating-that-the-version-does-not-exist)), but the
  156. solution below may be used in another use case.
  157. You can disable the import filter using the versions of installed packages with the option
  158. `extra.asset-optimize-with-installed-packages` in the root Composer package:
  159. ```json
  160. {
  161. "extra": {
  162. "asset-optimize-with-installed-packages": false
  163. }
  164. }
  165. ```
  166. #### Change/Disable the skip of versions by pattern
  167. By default, the plugin does not import the `patch` versions for increase dramatically
  168. performance. However, it is possible to change the pattern or to disable this feature.
  169. **Example for change the pattern:**
  170. ```json
  171. {
  172. "extra": {
  173. "asset-pattern-skip-version": "(-build)"
  174. }
  175. }
  176. ```
  177. **Example for disable the pattern:**
  178. ```json
  179. {
  180. "extra": {
  181. "asset-pattern-skip-version": false
  182. }
  183. }
  184. ```
  185. #### Disable the conjunctive option of the import filter
  186. You can disable the `conjunctive` mode of the import filter with the option
  187. `extra.asset-optimize-with-conjunctive` in the root Composer package:
  188. ```json
  189. {
  190. "extra": {
  191. "asset-optimize-with-conjunctive": false
  192. }
  193. }
  194. ```
  195. > **Note:**
  196. >
  197. > This option is used only if the optimization with the installed packages is enabled
  198. ### Define a custom directory for the assets installation
  199. By default, the plugin will install all the assets in the directory
  200. `vendors/{asset-type}-asset` and packages will be installed in each folder with
  201. their asset name.
  202. But you can change the installation directory of the assets directly in the root
  203. `composer.json`-file of your project:
  204. ```json
  205. {
  206. "extra": {
  207. "asset-installer-paths": {
  208. "npm-asset-library": "web/assets/vendor",
  209. "bower-asset-library": "web/assets/vendor"
  210. }
  211. }
  212. }
  213. ```
  214. > **Note:**
  215. >
  216. > For Bower, all files defined in the section `ignore` will not be installed
  217. ### Disable or replace the deleting of the ignore files for Bower
  218. For Bower, all files defined in the section `ignore` will be delete just after the
  219. installation of each package. Of course, this behavior can be disabled or replaced.
  220. **Example for disable the list of ignored files:**
  221. ```json
  222. {
  223. "extra": {
  224. "asset-ignore-files": {
  225. "bower-asset/example-asset1": false
  226. }
  227. }
  228. }
  229. ```
  230. **Example for replace the list of ignored files:**
  231. ```json
  232. {
  233. "extra": {
  234. "asset-ignore-files": {
  235. "bower-asset/example-asset1": [
  236. ".*",
  237. "*.md",
  238. "test"
  239. ]
  240. }
  241. }
  242. }
  243. ```
  244. ### Enable manually the deleting of the ignore files for NPM
  245. For NPM, there is no section `ignore`, but you can manually add the patterns for
  246. delete the files:
  247. ```json
  248. {
  249. "extra": {
  250. "asset-ignore-files": {
  251. "npm-asset/example-asset1": [
  252. ".*",
  253. "*.md",
  254. "test"
  255. ]
  256. }
  257. }
  258. }
  259. ```
  260. ### Use the Ignore Files Manager in the Composer scripts
  261. Sometimes you need to clean a package that is not considered an NPM/Bower Asset
  262. Package. To do this, you can use the script helper
  263. `Fxp\Composer\AssetPlugin\Composer\ScriptHandler::deleteIgnoredFiles` for the
  264. `post-package-install` or `post-package-update` script events.
  265. **Example:**
  266. ```json
  267. {
  268. "scripts": {
  269. "post-package-install": [
  270. "Fxp\\Composer\\AssetPlugin\\Composer\\ScriptHandler::deleteIgnoredFiles"
  271. ],
  272. "post-package-update": [
  273. "Fxp\\Composer\\AssetPlugin\\Composer\\ScriptHandler::deleteIgnoredFiles"
  274. ]
  275. },
  276. "extra": {
  277. "asset-ignore-files": {
  278. "acme/other-asset": [
  279. ".*",
  280. "*.md",
  281. "test"
  282. ]
  283. }
  284. }
  285. }
  286. ```
  287. ### Override the main files for Bower
  288. The bower.json specification allows packages to define entry-point files
  289. which can later be processed with taskrunners or build scripts. Some Bower
  290. plugins like main-bower-files, wiredep and asset-builder have a feature to
  291. override the package main files in the project configuration file.
  292. You can do the same with composer-asset-plugin, just add a section
  293. `asset-main-files` in the root project `composer.json` file with the package
  294. name and the files you want to mark as main files.
  295. **Example:**
  296. ```json
  297. {
  298. "extra": {
  299. "asset-main-files": {
  300. "acme/other-asset": [
  301. "other-asset.js"
  302. ]
  303. }
  304. }
  305. }
  306. ```
  307. ### Disable the search for an asset registry
  308. If you want to disable the search for an asset registry, you can add an extra
  309. option `extra.asset-registry-options.{type}-searchable` in the root project
  310. `composer.json`-file.
  311. **Example:**
  312. ```json
  313. {
  314. "extra": {
  315. "asset-registry-options": {
  316. "npm-searchable": false,
  317. "bower-searchable": false
  318. }
  319. }
  320. }
  321. ```