jaxwilko/wn-mix-plugin

Installs: 64

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 2

Forks: 1

Open Issues: 0

Type:winter-plugin

v1.0.2 2021-10-13 15:36 UTC

This package is auto-updated.

Last update: 2024-10-25 21:58:11 UTC


README

NOTICE: This plugin is now redundent since Winter v1.1.8. The functionality provided has been added to core, please see the docs.

Installation

Notice: NPN >=7.* is require for this plugin

We leverage the npm v7 feature workspaces to manage plugin resources from the application's root.

To set this up, you need to add the following to your root package.json:

"workspaces": {
    "packages": [
        "plugins/*/*",
        "themes/*"
    ]
}

Then run npm i. This can be done for you via the mix:install command.

Usage

Once installed, create a file at the root of a plugin or theme with the name winter.mix.js.

This file will be 90% the same as any laravel mix config file. However, you must set mix's publicPath.

Which you can do simply as:

mix.setPublicPath(__dirname);
// or
mix.setPublicPath(__dirname + '/assets');

For example if your plugin file structure was:

plugins/acme/myPlugin
  - assets
  - src
    - app.scss
  - Plugin.php

Then you could use the following in your winter.mix.js file:

let mix = require('laravel-mix');

mix.setPublicPath(__dirname + '/assets');

mix.sass('src/app.scss', 'app.css');

Compiling

Once you're all set up, you can use the mix command to run compilation.

Options:
  -l, --plugin[=PLUGIN]  Target a plugin.
  -t, --theme            Target the active theme.
  -d, --development      Run a development compile (this is default).
  -p, --production       Run a production compile.
  -w, --watch            Run and watch a development compile.
  -v                     Extra output

By default, the mix command runs in development mode, you can change this by using the --production flag.

You can only watch one thing at a time, so you must specify either --theme or --plugin author.plugin.

Examples

Compile theme assets:

  • ./artisan mix --theme
  • ./artisan mix --theme --production (for production)
  • ./artisan mix --theme --watch (in watch mode)

Compile plugin assets:

  • ./artisan mix --plugin jaxwilko.mix
  • ./artisan mix --plugin jaxwilko.mix --production (for production)
  • ./artisan mix --plugin jaxwilko.mix --watch (in watch mode)

Compile everything:

  • ./artisan mix
  • ./artisan mix --production (for production)