Code Monkey home page Code Monkey logo

adonis-mix-asset's Introduction

adonis-mix-asset

Laravel Mix for Asset Bundler on AdonisJs v5

typescript-image npm-image license-image

Adonis Mix Asset is assets bundler based on Laravel Mix for AdonisJs v5 application.

Laravel Mix is awesome assets bundler and easy to use!

If you need Laravel Mix for Adonis version lower than v5 you can use adonis-mix.

Table of contents

Getting Started

Installation

npm i --save-dev adonis-mix-asset laravel-mix@next

# or if using Yarn
yarn add --dev adonis-mix-asset laravel-mix@next

NOTE: We're using Laravel Mix v6.0.0-beta because the configuration already supported Typescript compilation with Babel. So we don't need to change the Webpack Config and create additional tsconfig.json in our AdonisJs v5 project.

Setup

node ace invoke adonis-mix-asset

It will install the provider, command, and copy webpack.mix.js configuration file to the project's root folder.

Usage

Example Configuration

The configuration file is on webpack.mix.js.

const mix = require('laravel-mix')

// NOTE: Don't remove this, Because it's the default public folder path on AdonisJs
mix.setPublicPath('public')

// Add your assets here
mix
  .js('resources/assets/scripts/app.js', 'scripts')
  .sass('resources/assets/styles/app.scss', 'styles')

For more information on Laravel Mix features. See Laravel Mix Documentation.

View Helper

Use mix view helper to generate assets url. Example :

...
<head>
  <link rel="stylesheet" href="{{ mix('styles/app.css') }}" />
  <script src="{{ mix('scripts/app.js') }}"></script>
</head>
...

The view helper parses mix-manifest.json to generate assets url.

Compile Assets

Make sure before you run the command, you already configuring the webpack.mix.js file, and run node ace serve or node ace build.

Build assets :

node ace mix:build

Build assets and watch for file changes :

node ace mix:watch

Build assets for production :

node ace mix:build --production

Additional Information

Gitignore

Add this to your .gitignore file :

mix-manifest.json

Also, for example if you want to output your scripts on public/scripts and styles on public/styles, you need to add all of those folders to your .gitignore file. Example :

public/scripts
public/styles

Analyze Assets Size

If you want to analyze all of your asset sizes for production. Run this command :

node ace mix:build --analyze --production

It will open your browser automatically and show an interactive treemap visualization of the contents of all your assets.

If the browser doesn't open automatically. You can open it on 127.0.0.1:8888.

Analyzer preview : webpack bundle analyzer zoomable treemap Source : webpack-bundle-analyzer documentation.

Enable Hot Module Replacement (HMR) / Hot Reloading

First, read Laravel Mix instructions about HMR.

Run this command to enable HMR :

node ace mix:watch --hot

Use Another Mix Configuration

If you want to use another Mix configuration, you can use --mix-config option either on mix:build or mix:watch. Example :

node ace mix:build --mix-config prod/webpack.mix.js
node ace mix:watch --mix-config prod/webpack.mix.js

adonis-mix-asset's People

Contributors

thetutlage avatar wahyubucil avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.