I
I
ildar-meyker2018-07-11 22:26:59
JavaScript
ildar-meyker, 2018-07-11 22:26:59

Does webpack make it possible to include the desired module in inline js, like requirejs does?

I am trying to start using webpack. I wrapped everything in modules, formed a bundle. But I have a piece of inline code on the page that depends on jquery. But webpack pulls jquery asynchronously and at the moment when the page execution reaches the inline script, jquery is not available. With requirejs it would look like this:

require([ 'jquery' ], function ($) {
    // делаю что-то, используя jquery
    console.log($);
});

What about webpack?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2018-07-11
@sergiks

One of the webpack developers recommends using ded/script.js :

var $script = require("scriptjs");
$script("//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js", function() {
  $('body').html('It works!')
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question