Y
Y
yabivipil2016-10-06 08:05:22
JavaScript
yabivipil, 2016-10-06 08:05:22

How to make two builds with and without jquery in webpack?

I need to generate two versions of a script. In one case, I need to make an assembly that includes jquery, in another case, I need jquery to be taken from the site where the script is located.

module.exports = {
  context: __dirname + "/web/js/",
  entry: {
    "full": full,
    "light": light
  },
  output: {
    path: __dirname + "/web/js/",
    filename: "[name].js"
  },
  resolve: {
    alias: resolves
  },
  library: 'client',
  plugins: [
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery'
    })
  ]
};

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
yabivipil, 2016-10-06
@yabivipil

Made as follows:
1. Made jqueryStub

define('jquery', [], function(){
    return window.$;
});

2.webpack.config.js
module.exports = [
{
...
  plugins: [
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery'
    })
  ]
},
{
...
  plugins: [
    new webpack.ProvidePlugin({
      $: __dirname + '/web/js/jqueryStub',
      jQuery: __dirname + '/web/js/jqueryStub'
    })
  ]
}
];

C
Cyber_bober, 2016-10-06
@Cyber_bober

Maybe this will help https://webpack.github.io/docs/library-and-externa...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question