question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal : mix.extractVendor() to auto extract

See original GitHub issue

Hi,

In one of my recent project; i had lots of 3rd party modules that needs to be extracted in a separate vendor.js file. Sometime it become hassle to to keep extract list up to date.

mix.extract(
	[
	  'package-1',
	  'package-2',
	  ....	
	  'package-50',
	]
);

I come up with this solution.

mix.webpackConfig({
  plugins: [
    // https://webpack.js.org/plugins/commons-chunk-plugin/
    new webpack.optimize.CommonsChunkPlugin({
      name: 'js/vendor',
      minChunks: function (module) {
        // This prevents stylesheet resources with the .css or .scss extension
        // from being moved from their original chunk to the vendor chunk
        if (module.resource && (/^.*\.(css|scss|less)$/).test(module.resource)) {
          return false;
        }
        return module.context && module.context.indexOf("node_modules") !== -1;
      }
    }),
    new webpack.optimize.CommonsChunkPlugin({
      name: 'js/manifest',
      minChunks: Infinity
    }),
  ]
});

Above code will auto extract all modules that are coming from node_modules to the vendor.js file. So; if you reference a module in your app.js like -

// app.js
import moment from 'moment';

In this case moment will be auto extracted to vendor.js.

Proposal Have another method mix.extractVendor() (may be a better name) that will do the above. This is similar to package discovery in Laravel, where you install a package and start using it in your code. You no need to tweak your webpack.mix.js file every time when add or remove a package.

vue-cli is doing the same already, see

Thanks.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
ankurk91commented, Dec 1, 2018
2reactions
ankurk91commented, Mar 14, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposal : mix.extractVendor() to auto extract · Issue #1233
Hi,. In one of my recent project; i had lots of 3rd party modules that needs to be extracted in a separate vendor.js...
Read more >
Library Code Splitting | Laravel Mix Documentation
One solution is to isolate, or extract, your vendor libraries into their own file. ... When not using mix.extract() , this code is...
Read more >
Vendor extraction yes or no? - Laracasts
https://laravel.com/docs/8.x/mix#vendor-extraction ... that you can leave extract() empty, and it will automatically extract ALL of your vendor libraries.
Read more >
Laravel Mix common chunk and vendor chunk - Stack Overflow
After having a look though the Laravel Mix source, I realised that the array provided to mix.js().extract() is just being used to create ......
Read more >
Extract Your Data - Tableau Help
For example, a pattern that specifies a mix of Gregorian year (y) and ISO week (ww) causes null values. Date scenario 1. Suppose...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found