Download the PHP package delaneymethod/craft-mix without Composer
On this page you can find all versions of the php package delaneymethod/craft-mix. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download delaneymethod/craft-mix
More information about delaneymethod/craft-mix
Files in delaneymethod/craft-mix
Package craft-mix
Short Description Helper plugin for Laravel Mix in Craft CMS templates.
License MIT
Informations about the package craft-mix
Helper plugin for Laravel Mix in Craft CMS templates.
Requirements
- Craft CMS 3.7+
- PHP
- Node.js 6+
Installation
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
-
Then tell Composer to load the plugin:
-
In the Craft Control Panel, go to Settings → Plugins and click the "Install" button for Craft Mix.
- Create a
package.json
file with the following contents to install Laravel Mix dependencies and configure asset build tasks.
Install the Node.js dependencies using npm
or yarn
.
Configuration
To configure Craft Mix go to Settings → Plugins → Craft Mix in the Craft Control Panel.
The available settings are:
- Public Path - The path of the public directory containing the index.php
- Asset Path - The path of the asset directory where Laravel Mix stores the compiled files
To demonstrate usage of the plugin, let's imagine a project with the following directory structure.
Create a webpack.mix.js
file at the root of your project to configure Laravel Mix for building your assets. See the Laravel Mix documentation for configuration details and more options. Be sure to configure the publicPath
option to point at the directory from which you will serve static assets (images, fonts, javascript and CSS). Here's an example configuration as a starting point that would work with the previously described project structure:
Usage
The primary purpose of this plugin is to provide template helpers that translate between a known path to your build assets and the real path to the assets after they have been built (which varies depending on the build mode). There are three main ways you can use Mix from Twig templates in CraftCMS:
There are a handful of different modes in which you can run Mix and the plugin will work differently in each mode, as described in the following sections.
Dev Mode
Dev mode will build your assets to target a development environment. Depending on how you've configured Mix, this may bypass certain build instructions intended only for the production environment. In the example webpack.mix.js
file, we are only versioning assets in production mode for cache busting or similar use cases. You can build the assets for developer mode by using the npm
script we added in our package.json
file:
Watch Mode
Functions just like Dev Mode except Mix will continue running as a foreground process through NodeJS and building assets as changes to the source files are detected.
Hot Module Replacement Mode
Builds your assets and runs the Webpack dev server to allow Hot Module Replacement. It works very similarly to what is described in the Laravel Mix documentation. To run in HMR mode, run the following command:
Production Mode
or bundle your assets for production
Credits
About DelaneyMethod
DelaneyMethod are a Full-Stack Web Development Agency with a no-nonsense, get it done attitude with a proven track record for delivering their part of a project. Learn more about us on our website.
License
The MIT License (MIT). Please see License File for more information.