Skip to content

Instantly share code, notes, and snippets.

@OwenMelbz
Last active April 17, 2019 21:36
Show Gist options
  • Save OwenMelbz/8f334f4b9504bafa545f96e000b18e9e to your computer and use it in GitHub Desktop.
Save OwenMelbz/8f334f4b9504bafa545f96e000b18e9e to your computer and use it in GitHub Desktop.
A single Laravel Mix for all your Nova components
const NovaWatcher = require('./NovaWatcher');
let mix = require('laravel-mix');
// ALL YOUR NORMAL MIX STUFF GOES HERE
new NovaWatcher(mix, './nova-components');
// The above will run the default nova webpack mix file for each component, allowing you to have a single watcher whilst developing!
const fs = require('fs');
const path = require('path');
module.exports = function NovaWatcher(context, component_path = null)
{
this.mix = context;
this.path = path.resolve(process.cwd(), (component_path || './nova-components'));
this.components = fs.readdirSync(this.path);
this.queueComponent = function (component)
{
const path = `${this.path}/${component}/resources/`;
this
.mix
.js(path + '/js/field.js', path + 'dist/js')
.sass(path + '/sass/field.scss', path + 'dist/css')
.webpackConfig({
resolve: {
symlinks: false
}
});
};
this.components.forEach(c => this.queueComponent(c));
};
@Producdevity
Copy link

this would only work for custom field, not for tools and resource-tools. any idea how we can detect this automatically?
An other way would be to pass and options object like:

{MyField: 'field', myResourceTool: 'resource-tool'}

and then determine the js/sass path based on the options passed.

What do you think about this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment