Created
August 29, 2018 03:16
-
-
Save alexciarlillo/8f301831721a3c2f773eb7b42a2c93e7 to your computer and use it in GitHub Desktop.
Artisan Runner Plugin For Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let exec = require('child_process').exec; | |
function ArtisanRunnerPlugin(options) { | |
this.startTime = Date.now(); | |
this.prevTimestamps = {}; | |
this.firstRun = true; | |
} | |
function puts(error, stdout, stderr) { | |
if (error) { | |
throw error; | |
} | |
console.log(stdout); | |
} | |
ArtisanRunnerPlugin.prototype.apply = function (compiler) { | |
compiler.plugin('compilation', function (compilation) { | |
if (this.firstRun) { | |
exec('php artisan view:make-angular', puts); | |
this.firstRun = false; | |
} | |
var changedFiles = Object.keys(compilation.fileTimestamps).filter(function (watchfile) { | |
return (this.prevTimestamps[watchfile] || this.startTime) < (compilation.fileTimestamps[watchfile] || Infinity); | |
}.bind(this)); | |
this.prevTimestamps = compilation.fileTimestamps; | |
changedFiles.forEach((changed) => { | |
if (changed === 'resources/views') { | |
exec('php artisan view:make-angular', puts); | |
} | |
}); | |
}.bind(this)); | |
}; | |
module.exports = ArtisanRunnerPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mix.webpackConfig({ | |
plugins: [ | |
new ArtisanRunnerPlugin(), | |
new ExtraWatchWebpackPlugin({ | |
dirs: [ 'resources/lang', 'resources/views' ] | |
}) | |
] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment