I
I
ivankirshin2019-01-14 20:01:16
webpack
ivankirshin, 2019-01-14 20:01:16

How to set up externals in webpack?

For the carousel on the site I use jq plugin Slick-carousel.

import $ from 'jquery';
import 'slick-carousel';
$('.subscribe-slider').slick({
...

Since we have many different bundles, it is necessary that third-party libraries are not added to them on sale.
To do this, add the following to the webpack config:
config.externals = [
        {
            vue: 'Vue',
            jquery: 'jQuery',
            vuex: 'Vuex',
        },
        'slick-carousel'
    ];

It is for a slick that this approach does not work, since it should not be exported to any variable, but simply processed. That is, it would be better if webpack just forgot about this import.
With such a config, the lib code is cut out of the bundle, but it still tries to import something, and everything falls down
5c3cc01e10663756497435.jpeg
. How can I do this correctly?

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