Code Monkey home page Code Monkey logo

laravel-mix-auto-extract's Introduction

Laravel Mix Auto Extract Vendors Plugin

downloads npm-version github-tag license

Laravel Mix plugin to auto extract 3rd party dependencies as vendor.js.

๐Ÿ“ฃ Notice: This feature has been added to Laravel Mix v4.0 now. ๐ŸŽ‰

What was the problem?

  • Laravel Mix already has a extract() method which accepts an array of dependencies that you want to extract as vendor.js
  • Whenever you install a new package, you also need to update this list to make it work.
  • Read more on this issue

How does this plugin solve above issue?

  • This plugin will auto extract all js dependencies coming from node_modules to vendor.js file.
  • You just need to reference them in your code somewhere. For example:
// app.js
import Vue from 'vue';
import axios from 'axios';
  • Now vue and axios will be auto extracted to vendor.js file

Requirements

Installation

# npm
npm install laravel-mix-auto-extract --save

# yarn
yarn add laravel-mix-auto-extract

Usage

Update your webpack.mix.js

const mix = require('laravel-mix');
// Require this package
require('laravel-mix-auto-extract');
// Your code may go here
// mix.js('./resources/assets/js/app.js', './public/js/app.js')
// mix.version()
// Call this method at last
mix.autoExtract();

Then update your blade template

<script src="{{ mix('js/manifest.js') }}"></script>
<script src="{{ mix('js/vendor.js') }}"></script>
<script src="{{ mix('js/app.js') }}"></script>

Remove any reference to extract() method in webpack.mix.js

Configuration Options

Here are the default options, all of them are optional.

mix.autoExtract({
  vendorPath: 'js/vendor', // Don't suffix paths with `.js`
  manifestPath: 'js/manifest',
  excludeRegExp: /^.*\.(css|scss|sass|less|styl)$/,
  generateManifest: true,
});

Paths are relative to the default output directory, usually ./public.

โš ๏ธ Caution

Don't use autoExtract() method along with extract() method.

Changelog

Please see CHANGELOG for more information what has changed recently.

License

MIT License

laravel-mix-auto-extract's People

Contributors

ankurk91 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-mix-auto-extract's Issues

mix.autoExtract errors out `mix.extend is not a function`

Hi, thank you for the package! I have the following versions in package.json:

"laravel-mix": "^1.7.2",
"laravel-mix-auto-extract": "^1.0.0"

But when I use the package as instructed:

require('laravel-mix-auto-extract');
...
mix.react(....).sass(...).version();
mix.autoExtract();

And compile for production I get the following error:

/home/forge/yoursite.com/node_modules/laravel-mix-auto-extract/src/index.js:4
mix.extend('autoExtract', new AutoExtract());
    ^

TypeError: mix.extend is not a function

Any idea how to fix it so it compiles correctly?

Error after following the guide: Cannot redefine property: tap

Using laravel-mix: "^2.1.11"
I couldn't find anything regarding this issue anywhere. Any thoughts? :)

.../node_modules/laravel-mix-auto-extract/node_modules/laravel-mix/src/helpers.js:21
Object.defineProperty(Array.prototype, 'tap', {
       ^

TypeError: Cannot redefine property: tap
    at Function.defineProperty (<anonymous>)
    at Object.<anonymous> (.../node_modules/laravel-mix-auto-extract/node_modules/laravel-mix/src/helpers.js:21:8)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (.../node_modules/laravel-mix-auto-extract/node_modules/laravel-mix/src/index.js:16:1)

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.