Module Overview
Drupal and Composer working together is great for management of external libraries, that can be integrated into Drupal sites. It is a good practice to have the /vendor directory outside the webroot. The problem with moving the vendor out of the webroot however comes when trying to provide public URLs to files in the /vendor directory, such as CSS or JS files that are part of an external library.
This module provides a new stream wrapper, vendor://
, that allows for referencing of files in the vendor directory. It works much the same as the private://
file wrapper provided by Drupal core. Along with this stream wrapper, this module sets up *.libraries.yml files to be parsed for vendor://
references, as can be seen in the code below.
example.libraries.yml:
some_library:
js:
vendor://vendor-name/package-name/js/some_file.js: {}
css:
theme:
vendor://vendor-name/package-name/css/some_file.css: {}
The module also provides a helper function, vendor_stream_wrapper_create_url()
for resolving vendor files to public facing URLs:
$public_url = vendor_stream_wrapper_create_url('vendor://vendor/package/file.css');
Configuration
This module will look first for the vendor first at ./vendor
then at ../vendor
. If no vendor folder is found, the system will crash. To fix this, set the location of the vendor folder path in settings.php as follows:
$settings['vendor_file_path'] = 'path/to/vendor/folder';
To prevent unwanted behavior (i.e., exposing files without a site owner's knowledge or intention), file/directory patterns should be explicitly provided by navigating to '/admin/config/media/vendor-stream-wrapper'. Indicate the patterns of files/directories located in the vendor directory that should be publically accessible.
Note: by default, no files can be downloaded using example.com/vendor_files/filename.ext, but the ://vendor stream wrapper (within the code) still works as expected.
Project information
- Module categories: Developer Tools
- Ecosystem: YMCA Website Services (former Open Y) Community Edition
- 1,132 sites report using this module
- Created by Jaypan on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.