Laravel Mix for AdonisJS
Adonis Mix is assets bundler your AdonisJs application.
It's based on Laravel Mix which is a super easy tool to configure webpack
.
This package should be installed with the Adonis CLI.
$ adonis install adonis-mix
Then register the Service Provider within your start/app.js
file.
const providers = [
'adonis-mix/providers/AssetsProvider',
]
You are now ready to go!
On installation adonis-mix
copies webpack.mix.js
configuration file to the project's root folder. See See Laravel Mix Documentation to how to setup your assets.
After creating your assets in the way you want (Less, SCSS, Stylus, ES2015, ...) you simply need to run the command below and the magic will happen.
$ adonis assets
# adonis assets --watch -> Watch for change
# adonis assets --production -> Minify for production
Laravel Mix will automaticaly download packages you need to compiles your assets and will then run them.
The config file is Laravel Mix webpack.mix.js
file.
For simple AdonisJS project you can use following configuration
const mix = require('laravel-mix')
mix.setPublicPath('public')
mix
.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/scss/app.scss', 'public/css')
Add these to webpack.mix.js
file in project's root.
Read Laravel Mix instructions about HMR.
You can add script to your package.json
...
"scripts": {
...
"hot": "webpack-dev-server --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js"
...
}
...
And run dev server with
npm run hot
Also this package adds mix
view helper, that parses mix-manifest.json
file to generate urls to assets.
...
<head>
{{ style(mix('css/app.css')) }}
{{ script(mix('js/app.js)) }}
</head>
...