Download the PHP package lcharette/webpack-encore-twig without Composer

On this page you can find all versions of the php package lcharette/webpack-encore-twig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package webpack-encore-twig

Webpack Encore Twig Integration

Version PHP Version Build Codecov StyleCI PHPStan Donate

Webpack Encore Standalone Twig Functions. Allows usage of Webpack Encore in Twig Templates without Symfony. Optimized for PHP-DI style containers.

This allows you to use the splitEntryChunks() and enableVersioning() features from Webpack Encore by reading the entrypoints.json and manifest.json files.

Installation

Documentation & Usage

Whenever you run Encore, two configuration files are generated in your output folder (default location: public/build/): entrypoints.json and manifest.json. Each file is similar, and contains a map to the final, versioned filenames.

The first file – entrypoints.json – is generated when the splitEntryChunks() option is defined in your webpack.config.js and will be read by the encore_entry_script_tags() and encore_entry_link_tags() Twig helpers this package provides. If you're using these, then your CSS and JavaScript files will render with the new, versioned filename.

The second file - manifest.json - is generated when Asset Versioning option (enableVersioning()) is defined in your webpack.config.js and will be read to get the versioned filename of other files, like font files or image files (though it also contains information about the CSS and JavaScript files).

Both features (splitEntryChunks() and enableVersioning()) are defined as two separate Twig Extensions (EntrypointsTwigExtension and VersionedAssetsTwigExtension respectively) in case you need/want to enable only one of the two.

splitEntryChunks and entrypoints.json

Encore writes an entrypoints.json file that contains all of the files needed for each "entry". To reference entries in Twig, you need to add the EntrypointsTwigExtension extension to the Twig Environment. This accept EntrypointLookup, which itself accept the path to the entrypoints.json, and the TagRenderer (which itself accept EntrypointLookup).

Now, to render all of the script and link tags for a specific "entry" (e.g. entry1), you can:

If you want more control, you can use the encore_entry_js_files() and encore_entry_css_files() methods to get the list of files needed, then loop and create the script and link tags manually.

Custom Attributes on script and link Tags

Custom attributes can be added to rendered script or link in 3 different ways:

  1. Via global config, using the defaultAttributes argument on the TagRenderer constructor, or using the setter method:

  2. Via specific script or link argument on the TagRenderer constructor, or using the setter method:

  3. When rendering in Twig - see the attributes option in the docs above.

enableVersioning and manifest.json

To read the manifest file to be able to link (e.g. via an img tag) to certain assets, you need to add the VersionedAssetsTwigExtension extension to the Twig Environment. This accept JsonManifest, which itself accept the path to the manifest.json.

In your Twig template, just wrap each path in the Twig asset() function like normal:

Dependency Injection & Autowiring

When using a PSR Dependency Injection Container with autowiring, like PHP-DI, you can define EntrypointLookup and JsonManifest in your definition factory via their respective interface (EntrypointLookupInterface and JsonManifestInterface). For example :

EntrypointsTwigExtension and VersionedAssetsTwigExtension can then be injected into your other classes via the container :

Using Without Twig

Both script and link tags can be generated in vanilla PHP and without Twig using the underlying public methods on the TagRenderer class:

Getting script and link tag from entrypoints.json:

Same goes for the versioned assets, using the underlying public methods on the JsonManifest class:

Getting versioned from manifest.json:

See Also

References


All versions of webpack-encore-twig with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
symfony/webpack-encore-bundle Version ^1.13|^2.1
twig/twig Version ^3.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lcharette/webpack-encore-twig contains the following files

Loading the files please wait ....