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

laravel-mix-serve

v2.2.2

Published

Extends Laravel Mix to run the Laravel, or custom, serve command.

Downloads

924

Readme

Laravel Mix Serve

Software License Latest Version on NPM npm

This package extends Laravel Mix to run the php artisan serve command by default, or any custom command, within the same shell after the mix command has been executed.

Table of Contents


  1. Usage
  2. Configuration
    • Defaults
    • Commands
    • Verbosity
    • Watch (ver 2.1.0)
    • Development (ver 2.1.0)
    • Production (ver 2.1.0)
    • Hook (ver 2.2.0)
  3. Credits
  4. License (MIT)

Usage

Back to Top


  1. Install the package with npm or yarn:
npm install laravel-mix-serve --save-dev

yarn add laravel-mix-serve --dev
  1. Require the extension in your Mix configuration:
const mix = require('laravel-mix');

require('laravel-mix-serve');
  1. Enable the extension by calling .serve():
mix.serve();

By default, the Laravel serve command php artisan serve will be executed.

And you're done!

Configuration

Back to Top


Defaults

mix.serve({
    cmd: 'php',
    args: ["artisan", "serve"],
    verbose: true,
    watch: true,
    dev: true,
    prod: false
})

The use of an Object, for the command (cmd) and arguments (args), comes from the way that the spawn method of the child_process module is used.

Commands

- String Commands

Instead of making changes directly to the Object, you can provide a string command. Configuration options can still be changed through the second parameter.

// String Command
mix.serve('php artisan serve');

//String Command with Any Config Options
mix.serve('php artisan serve', {
    verbose: true,
    watch: true,
    dev: true,
    prod: false
});

Since the configuration options passed to the second parameter would take precedence when assigned, the cmd and args properties within the second parameter Object are deleted to ensure that the string command is not overwritten.

- Custom Commands

Custom commands are the major caveat of this plugin, whether it is a custom Laravel or even non-Laravel command, in conjunction with the convenience of passing commands as strings.

// Custom Non-Laravel Command
mix.serve('npm run start');

// Custom Laravel Command
mix.serve('php artisan serve --port=8888');

Verbosity

You can choose whether you want the output from your server to show in the shell. By default, verbose is set to true so that you can see any responses or errors from your server. Otherwise, you can turn this feature off by setting verbose to false.

/* Options ( true | false | 'once' ) */

// Object
mix.serve({ verbose: false });

// with String Command
mix.serve('npm run start', { verbose: false });

For Laravel users, if you want to still be sure that your server is up while not losing the place of your compiled mix output, you can also use the option 'once'.

For example, if you only want the default Laravel output of:

Starting Laravel development server: http://127.0.0.1:8000

Watch (ver 2.1.0)

You can disable the command execution from running when watch has been called. By default it is enabled, since that is the intention of this plugin, especially when working in conjunction with BrowserSync.

// Object
mix.serve({ watch: false });

// with String Command
mix.serve('npm run start', { watch: false });

Development (ver 2.1.0)

You can disable the command execution from running in development mode when watch has not been called.

// Object
mix.serve({ dev: false });

// with String Command
mix.serve('npm run start', { dev: false });

To be specific, the logic by which development mode is determined, is when mix.inProduction() returns false.

Production (ver 2.1.0)

You can enable the command execution to run in production mode. By default, it is disabled since I have yet to determine the use case for this feature. It exists since the barebones came from the development of the dev option.

// Object
mix.serve({ prod: true });

// with String Command
mix.serve('npm run start', { prod: true });

Hook (ver 2.2.0)

You can choose on which compiler hook your command should run. By default, the command will run on the afterCompile hook.

// Object
mix.serve({ hook: 'beforeCompile' });

// with String Command
mix.serve('npm run start', { hook: 'beforeCompile' });

You can see all of the options available on the Webpack website.

Credits

Back to Top

Thank you Jeffrey, Laracasts built the foundation of my coding knowledge and techniques. There is such beauty to clean and readable code.

Laravel Mix has been godsend, even outside of the Laravel ecosystem. I have used it to set up quick template projects and it has saved me so much time.

This Laravel Mix Plugin is a small dedication to both what I learned in Laracasts and the wonderful tool that is Laravel Mix.

License

Back to Top

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