Skip to content

Instantly share code, notes, and snippets.

@helmerdavila
Last active April 17, 2018 22:22
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 helmerdavila/8045b4520be253461055f5e35170a924 to your computer and use it in GitHub Desktop.
Save helmerdavila/8045b4520be253461055f5e35170a924 to your computer and use it in GitHub Desktop.
Laravel Mix function for Adonis Edge views

Use this code in start/hooks.js

const { hooks } = require('@adonisjs/ignitor');
// Import the mix manifest file
const manifest = require('../public/mix-manifest');

hooks.after.providersBooted(() => {
  const View = use('View');

  // Creating the mix function in edge views
  View.global('mix', function (asset) {
    if (!manifest[`/${asset}`]) {
      return '404-asset-not-found';
    }

    return manifest[`/${asset}`];
  })
});

Then, restart the server, and you can use in your edge views

{{ css(mix('css/your-styles.css')) }}

or

<link href="{{ mix('css/your-styles.css') }}" rel="stylesheet">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment