Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit e0f68b2

Browse files
committed
Add all included php files as Webpack dependencies
- Support cacheable loaders and watch mode https://github.com/webpack/docs/wiki/how-to-write-a-loader#mark-dependencies
1 parent 9f413cc commit e0f68b2

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ module.exports = function(content){
3636
args.push(options.proxy);
3737
}
3838

39+
this.addDependency(resource);
40+
args.push(resource);
41+
3942
if (options.args) {
4043
args = args.concat(options.args);
4144
}
4245

43-
this.addDependency(resource);
44-
args.push(resource);
45-
4646
let callback = this.async();
4747
let debug = options.debug;
48-
let cmd = 'php '+shellescape(args);
48+
let cmd = `php -r 'require $argv[1]; echo PHP_EOL, json_encode(get_included_files());' ${shellescape(args)}`;
4949
async function runPhp() {
5050
if(debug){
5151
console.log(cmd);
@@ -61,6 +61,15 @@ module.exports = function(content){
6161
callback(stderr);
6262
}
6363
else{
64+
// Split out last line which contains list of included files and add them as Webpack dependencies
65+
const includedSeparator = stdout.lastIndexOf('\n');
66+
const dependencies = stdout.slice(includedSeparator);
67+
stdout = stdout.slice(0, includedSeparator);
68+
69+
JSON.parse(dependencies).forEach(function(dependency) {
70+
self.addDependency(dependency)
71+
});
72+
6473
callback(null, stdout);
6574
}
6675

0 commit comments

Comments
 (0)