Skip to content

How to bundle vendor scripts separately and require them as needed with Webpack? #1087

Closed

Description

@bensampaio

Maybe this is not the right place to ask this, but I'm really in need of help here. I posted this question on stackoverflow yesterday, could you please have a look at it?

Thank you!

Activity

  1. margielm commented on May 20, 2015

    @margielm

    I don't consider myself webpack-expert. but I tried to do my best to help you.

  2. bebraw commented on Nov 14, 2015

    @bebraw
    Contributor

    @bensampaio Did you figure this out?

  3. bensampaio commented on Nov 21, 2015

    @bensampaio
    Author

    @bebraw In the end I decided to keep doing it as before... I use webpack for my own scripts, and I merge all vendor scripts into one even if some of them are not used. I don't like it, but it works... I tried to create a loader to just grab all required vendor scripts and merge them in a file by keeping global variables, but it had some problems with the order files were being loaded and written. I ended up giving up because it was consuming too much time. If you want to have a look you can find it here: https://github.com/bensampaio/webpack-globals-loader.

  4. Freezystem commented on Apr 19, 2016

    @Freezystem

    In case you're interested in bundling automatically your scripts separately from vendors ones:

    var webpack = require('webpack'),
        pkg     = require('./package.json'),  //loads npm config file
        html    = require('html-webpack-plugin');
    
    module.exports = {
      context : __dirname + '/app',
      entry   : {
        app     : __dirname + '/app/index.js',
        vendor  : Object.keys(pkg.dependencies) //get npm vendors deps from config
      },
      output  : {
        path      : __dirname + '/dist',
        filename  : 'app.min-[hash:6].js'
      },
      plugins: [
        new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.min-[hash:6].js'),
        new html({template : __dirname + '/app/index.html'})
      ]
    };

    You can read more about this feature in official documentation.

  5. KongMac commented on Apr 19, 2016

    @KongMac

    You can put the vendor scripts into the other folder,not in the entry folders.you just use "require (XX)"in the entry file,and then you make it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions