Last active
April 17, 2019 21:36
-
-
Save OwenMelbz/8f334f4b9504bafa545f96e000b18e9e to your computer and use it in GitHub Desktop.
A single Laravel Mix for all your Nova components
This file contains hidden or 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
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! |
This file contains hidden or 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
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)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?