Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Artisan Runner Plugin For Angular
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;
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