Giter VIP home page Giter VIP logo

asset-mix's Introduction

AssetMix plugin for CakePHP

Latest Stable Version Total Downloads License CakePHP Tests PHPStan Check Coding Style Check

Provides integration with your CakePHP application & Laravel Mix.

This branch works with CakePHP 4.0+, see version map for more details.

Installation

  1. Get project into your system

    Via composer:

    composer require ishanvyas22/asset-mix
  2. Load plugin using below command:

    bin/cake plugin load AssetMix
  3. Generate basic Javascript, CSS & Sass scaffolding:

    bin/cake asset_mix generate

    Note: Above command will generate scaffolding for vue, but you can generate Bootstrap/jQuery, React or Inertia scaffolding too.

  4. Install frontend dependencies

    npm install

    or

    yarn install
  5. Compile your assets

    • For development:
    npm run dev
    • To watch changes:
    npm run watch
    • For production:
    npm run prod
  6. Load AssetMix helper from the plugin into your AppView.php file:

    $this->loadHelper('AssetMix.AssetMix');

Usage

After compiling your assets(js, css) with laravel mix, it creates a mix-manifest.json file into your webroot directory which contains information to map the files.

  • To generate script tag for compiled javascript file(s):
echo $this->AssetMix->script('app');

Above code will render:

<script src="/js/app.js" defer="defer"></script>

As you can see it works same as Html helper. There is not need to provide full path or even file extension.

  • To generate style tag for compiled css file(s):
echo $this->AssetMix->css('main');

Output:

<link rel="stylesheet" href="/css/main.css">

If versioning is enabled, output will look something like below:

<link rel="stylesheet" href="/css/main.css?id=9c4259d5465e35535a2a">

Generate command

Generate command is used to auto generate basic scaffolding to quickly start developing and using the assets into your project.

Get help:

bin/cake asset_mix -h

Generate default scaffolding:

bin/cake asset_mix generate

Above command will generate:

  • package.json
  • webpack.mix.js
  • assets/
    • css/
    • js/
    • sass/

assets/ directory is where you will store your js, css files which will compile down into your respective webroot/ directory.

Custom directory name:

bin/cake asset_mix generate --dir=resources

You can also use custom directory name instead of default assets directory, above command will create resources directory where you can put your js, css, etc asset files.

Don't want to use Vue.js? Don't worry this plugin doesn't dictate on which javascript library you should use. This plugin provides ability to quickly generate scaffolding for Vue as well as Bootstrap, and React.

Generate basic Bootstrap/jQuery scaffolding:

bin/cake asset_mix generate bootstrap

Generate React scaffolding:

bin/cake asset_mix generate react

Generate scaffolding for Inertia.js:

bin/cake asset_mix generate inertia-vue

Generate React scaffolding inside resources directory:

bin/cake asset_mix generate react --dir=resources

Version map

AssetMix version Branch CakePHP version PHP minimum version
1.x master >=4.0.0 >=7.2
0.x cake3 >=3.5.0 >=5.6

❤️ Support The Development

Do you like this project? Support it by donating:

Buy Me A Coffee

or Paypal me

Changelog

Please see CHANGELOG for more information about recent changes.

Reference

To see this plugin into action you can refer to this project, which will provide more insight.

License

The MIT License (MIT). Please see License File for more information.

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.