Ignore

Plugin for ignoring module(s) from being bundled with IgnorePlugin.
latest v1.0.1 - released
erutan409
13 downloads last week
MIT license
2 versions
IgnorePlugin

Laravel Mix Ignore
npm npm

Ignore specific module(s) when bundling assets, using Laravel Mix.

Read more about how ignoring module(s) work with the IgnorePlugin.

Installation

npm install laravel-mix-ignore --save-dev

Parameters

Parameter Type
resource String | RegExp | Function
context (optional) String | RegExp | Function

When a String is given for either parameter, it's automatically converted to a RegExp instance.

So, target/with/slashes is converted to: /target\/with\/slashes/.

Usage

The resource parameter is tested against the string passed to require or import within the source code where the import is taking place.

const mix = require('laravel-mix');
require('laravel-mix-ignore');

// ignore bundling the following module
mix.ignore('import-or-require-statement-to-ignore', 'only-when-in-this-context');

Following with the official documentation on the IgnorePlugin, you can also pass in filter functions for either the resource or context parameters.

As stated in the documentation, the filter function(s) must return a Boolean value for the plugin to evaluate.

mix.ignore(
    resource => resource == 'import-or-require-statement-to-ignore',
    context => context == 'when-in-this-folder' // optional (without will be unconstrained)
);

Adapting the official documentation's examples when dealing with moment locales, in order to properly ignore bundling them when importing or requiring moment, do the following:

With the following import statement with how moment imports its locale(s)...

require('./locale/' + name);

...the first resource parameter should match against ./locale and the second context parameter should specify the directory or directories from where the import took place. The following will cause the locale files to be ignored in the proper context:

mix.ignore(
    /^\.\/locale$/,
    /moment$/
);