Martin Dawson
Martin Dawson

Reputation: 7656

webpack don't load dependencies

I have a problem where I am including a jQuery plugin (jquery.jplayer.js) and webpack is loading the dependencies of that plugin in the same file, in this case it's jQuery. I am wanting to serve jQuery by CDN so obviously I don't want jQuery loaded locally as well. I have narrowed it down to this line of code define(['jquery'], factory); // jQuery Switch.

How can I tell webpack to not include the dependencies that it finds in the .js files?

var debug = process.env.NODE_ENV !== "production";
var webpack = require("webpack");
var path = require("path");

module.exports = {
    context: __dirname,
    devtool: debug ? "inline-sourcemap" : null,
    entry: {
        app: "./wwwroot/js/app.js",
        lib: "./wwwroot/lib/jPlayer/dist/jplayer/jquery.jplayer.js"
    },
    module: {
        loaders: [
          {
              test: /\.jsx?$/,
              exclude: /(node_modules|bower_components)/,
              loader: "babel-loader",
              query: {
                  presets: ["react", "es2015", "stage-0"],
                  plugins: ["react-html-attrs", "transform-class-properties", "transform-decorators-legacy"],
              }
          }
        ]
    },
    output: {
        path: "./wwwroot/build/",
        filename: "[name].js"
    },
    plugins: debug ? [] : [
      new webpack.optimize.DedupePlugin(),
      new webpack.optimize.OccurenceOrderPlugin(),
      new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false })
    ]
};

Upvotes: 0

Views: 247

Answers (2)

Jorawar Singh
Jorawar Singh

Reputation: 7621

You could use provide plugin in webpack

 new webpack.ProvidePlugin({
     $: "jquery",
     jQuery: "jquery"
 })

Upvotes: 0

Martin Dawson
Martin Dawson

Reputation: 7656

This code excluded jQuery from being bundled:

externals: {
  "jquery": "jQuery"  
},

Upvotes: 1

Related Questions