T
T
tonyshow2019-04-01 14:55:47
webpack
tonyshow, 2019-04-01 14:55:47

How in webpack to store the name of the included jQuery libraries globally, for example $.dateRangePicker instead of the name of the webpackom inline?

Hello colleagues!
How to store the names of included libraries in the global scope in webpack?
For example, I compile all the libraries into one file and in it the jQuery library and the dateRangePicker plugin for it, which is accessed both in the main app.js script file and in external html files, jquery brought to the global scope, but here the dateRangePicker plugin as a method it is missing:
5ca1fae10bdda116724109.jpeg
Here is the Webpack config code:

{
      context:  params.path.src,
      entry: {
        app: [
          "webpack/hot/dev-server",
          (`${__dirname}/src/index.js`)
        ],
        global: [
          "webpack/hot/dev-server",
          (`${__dirname}/src/global.js`)
        ],
      },
      output: {
        filename: params.$.isDev ? `[name].js` : `[name].[hash].js`,
        publicPath: params.$.isDev ? `http://${params.devServer.host}:${params.devServer.port}${params.path.publicPath}` : params.path.publicPath,
        path: path.join(params.path.public, params.path.assets),
      },
      plugins: [
        new webpack.ProvidePlugin({
          $: 'jquery',
          jQuery: 'jquery',
          moment: 'moment',
        }),
      ]
    },

Here is app.js code:
import $ from 'jquery';
import moment from 'moment';
import 'jquery-ui';
import 'jquery-ui/themes/base/all.css';
import 'jquery-ui-touch-punch';
import dateRangePicker from 'jquery-date-range-picker';
import 'jquery-date-range-picker/dist/daterangepicker.min.css';
import 'lazyload';
import IMask from 'imask';

window.$ = $;
window.jQuery = $;
window.moment = moment;
// window.dateRangePicker = dateRangePicker;

In external HTML, scripts fire on a custom event that signals that the app.js script has been fully loaded and executed.
Thank you all in advance for your help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question