I
I
ildar-meyker2019-11-19 17:23:23
webpack
ildar-meyker, 2019-11-19 17:23:23

Can't globally declare jquery in laravel mix. Why?

I have simplified the code as much as possible.
1) As such, jquery is globally reachable. This is the original state.
app.js

import $ from "jquery";

window.$ = window.jQuery = $;

import { LessMore } from "./modules/less-more";

LessMore.init();

2) It was necessary to add chosen, and the code changed like this. I must say, chosen does not implement a modular approach, it expects that window.jQuery already exists by the time the code is executed, and therefore falls.
app.js
import $ from "jquery";

window.$ = window.jQuery = $;

import { LessMore } from "./modules/less-more";
import "chosen-js";

LessMore.init();

Apparently, laravel mix raises import to the top. How to achieve the desired result?

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