npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

adonis-mix-asset

v3.0.0

Published

Laravel Mix for Asset Bundler on AdonisJS

Downloads

416

Readme

Adonis Mix Asset

Laravel Mix for Asset Bundler on AdonisJS

npm-image license-image typescript-image

Adonis Mix Asset is an assets bundler based on Laravel Mix for AdonisJS application.

Laravel Mix is an awesome assets bundler and easy to use!

Table of contents

Getting Started

Installation

npm i adonis-mix-asset && npm i --save-dev laravel-mix

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

Setup

node ace configure 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')

/**
 * By default, AdonisJS public path for static assets is on the `./public` directory.
 *
 * If you want to change Laravel Mix public path, change the AdonisJS public path config first!
 * See: https://docs.adonisjs.com/guides/static-assets#the-default-directory
 */
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

Tips on Using Typescript Asset

If you're planning to use Typescript asset for your Front-End, here are some tips to get started.

For example if you want to put your scripts on resources/assets/scripts, then you need to create tsconfig.json in those folder. That way, it will prevent conflict between your Front-End script and Back-End script.

Here's an example tsconfig.json you can use :

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "noUnusedLocals": true,
    "incremental": true,
    "noUnusedParameters": true,
    "declaration": false,
    "strictNullChecks": true
  },
  "include": ["./"]
}