adonis-mix

1.2.0 • Public • Published

adonis-mix

Laravel Mix for AdonisJS

NPM Badge

Adonis Mix is assets bundler your AdonisJs application.

It's based on Laravel Mix which is a super easy tool to configure webpack.

Getting Started

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!

Bundle the assets

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 --prod -> Minify for production 

Laravel Mix will automaticaly download packages you need to compiles your assets and will then run them.

Config

The config file is Laravel Mix webpack.mix.js file.

Example configuration

For simple AdonisJS project you can use following configuration

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.

Hot Module Replacement

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

View Helper

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>
...

Package Sidebar

Install

npm i adonis-mix

Weekly Downloads

6

Version

1.2.0

License

MIT

Unpacked Size

8.2 kB

Total Files

9

Last publish

Collaborators

  • deathman92