Setting up external libraries using laravel mix

I need to use an external library in a webpack with laravel-mix. In a webpack I have to do something like this as described in the web docs

{
    output: {
        // export itself to a global var
        libraryTarget: "var",
        // name of the global var: "Foo"
        library: "Foo"
    },
    externals: {
        // require("jquery") is external and available
        //  on the global var jQuery
        "jquery": "jQuery"
    }
}

      

But can I do it with laravel mix?

+3


source to share


1 answer


In file webpack.mix.js

Only below

let mix = require('laravel-mix');

      

Add the following code



mix.webpackConfig({
    externals: {
        "jquery": "jQuery"
    }
});

      

Add any other external as needed. For example, I decided to load external React and ReactDOM, so my config is

mix.webpackConfig({
    externals: {
        "react": "React",
        "react-dom": "ReactDOM"
    }
});

      

Note that you can override any default webpack config inside the parameter object mix.webpackConfig

just like we did externals

here

+1


source







All Articles