phulp-inject
The inject addon for PHULP., (*1)
It's like gulp-inject with some modifications., (*2)
Install
$ composer require reisraff/phulp-inject
Usage
The target file src/index.html:, (*3)
Each pair of comments are the injection placeholders, (*4)
<!DOCTYPE html>
<html>
<head>
<title>App</title>
</head>
<body>
</body>
</html>
The phulpfile.php:, (*5)
<?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:, (*6)
<!DOCTYPE html>
<html>
<head>
<title>App</title>
<link rel="stylesheet" href="css/sytle.css">
<link rel="stylesheet" href="css/style2.css">
</head>
<body>
</body>
</html>
Options
Set in the constructor., (*7)
tagname : default: inject, it is used to define a global tagname as placeholder., (*8)
starttag : default: null, it is used to replace the default starttag, (*9)
endtag : default: null, it is used to replace the default endtag, (*10)
filterFilename : default: null, it is used to replace the filename, (*11)
<?php
use Phulp\Inject\Inject;
$cssMinifier = new Inject(
$distFiles,
[
'tagname' => 'replace-inject',
'starttag' => '<-- replace-inject -->',
'endtag' => '<-- endreplace-inject -->,
'filterFilename' => function ($filename) {
return 'path/' . $filename;
},
]
);