The inject addon for PHULP.
It's like gulp-inject with some modifications.
$ composer require reisraff/phulp-inject
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>
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;
},
]
);