Skip to content

Instantly share code, notes, and snippets.

@alexciarlillo
Created August 29, 2018 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexciarlillo/8f301831721a3c2f773eb7b42a2c93e7 to your computer and use it in GitHub Desktop.
Save alexciarlillo/8f301831721a3c2f773eb7b42a2c93e7 to your computer and use it in GitHub Desktop.
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