reisraff / phulp-inject
The inject addon for phulp
1.1.0
2016-10-27 23:56 UTC
Requires
- reisraff/phulp: ~1.7
This package is auto-updated.
Last update: 2024-11-28 03:50:15 UTC
README
The inject addon for PHULP.
It's like gulp-inject with some modifications.
Install
$ composer require reisraff/phulp-inject
Usage
The target file src/index.html
:
Each pair of comments are the injection placeholders
<!DOCTYPE html> <html> <head> <title>App</title> <!-- inject:css --> <!-- endinject --> </head> <body> <!-- inject:js --> <!-- endinject --> </body> </html>
The phulpfile.php
:
<?php use Phulp\Inject\Inject; $phulp->task('inject', function ($phulp) { $injectionFiles = $phulp->src(['src/'], '/(js|css)$/', true); $phulp->src(['src/'], '/html$/') // injecting ->pipe(new Inject($injectionFiles->getDistFiles())) // write the html file with the injected files ->pipe($phulp->dest('dist/')); });
dist/index.html
after running phulp inject
:
<!DOCTYPE html> <html> <head> <title>App</title> <!-- inject:css --> <link rel="stylesheet" href="css/sytle.css"> <link rel="stylesheet" href="css/style2.css"> <!-- endinject --> </head> <body> <!-- inject:js --> <script src="js/script.js"></script> <script src="js/script2.js"></script> <!-- endinject --> </body> </html>
Options
Set in the constructor.
tagname : default: inject, it is used to define a global tagname as placeholder.
starttag : default: null, it is used to replace the default starttag
endtag : default: null, it is used to replace the default endtag
filterFilename : default: null, it is used to replace the filename
<?php use Phulp\Inject\Inject; $cssMinifier = new Inject( $distFiles, [ 'tagname' => 'replace-inject', 'starttag' => '<-- replace-inject -->', 'endtag' => '<-- endreplace-inject -->, 'filterFilename' => function ($filename) { return 'path/' . $filename; }, ] );