mbraak/jqTree

Feature: ES6 support

Closed this issue · 9 comments

In vite development mode sources are loaded as ES6 modules, which this library does not support. Would be lovely to have that available as well.

Or rather, even a proper wrapper fixed it for me (copied from a library that works with vite command):

;(function ($, window, document, undefined) {
...
})( jQuery, window, document );
mbraak commented

I'll have look

mbraak commented

I tried to use Vite js with jqTree and it works. See https://github.com/mbraak/vite-jqtree-demo

I didn't make any changes to jqTree.

Thank you. It is indeed our own configuration issue and I aplogize. We had: condition "include: **/*.js" to make sure it is only injected into JS files (it tries to insert into scss otherwise), however that mapping doesn't work with node_modules then and was then not injecting it properly. Will adjust it accordingly

Unfortunately I must re-open this case. It seemed to work since I was probably only testing it in development mode, which it did not work before due to my own error (previous error was about missing jquery). However, if I run vite build/npm run build, then it throws error about "require is not defined":

app-d21daea4.js:15 Uncaught ReferenceError: require is not defined
    at app-d21daea4.js:15:15490
    at app-d21daea4.js:1:23
    at app-d21daea4.js:17:17925
...
    Yt.JqTreeWidget = void 0;
    var Bs = Me(require("./version")) <-

If I run vite/npm run dev then it works.

I am made a sample barebone Laravel project: https://github.com/TivoSoho/laravel-jqtree There is essentially nothing there, but we use it in laravel context in case it matters. This is the config:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import inject from "@rollup/plugin-inject";

export default defineConfig({
    plugins: [
        inject({
            $: 'jquery',
            jQuery: 'jquery',
        }),
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
    ],
});

and this is the app.js:

import './bootstrap';
import $ from 'jquery';

window.$ = $;
window.jQuery = $;

import 'jqtree';

Any suggestions as to what I might be doing wrong, what is missing for it to work?

mbraak commented

I made a branch in the jqtree repository with a fix: #739

In my vite project I changed the jqtree dependency to:

"jqtree": "https://github.com/mbraak/jqTree.git#change-bundle-in-package"

Can you check if this works for you? It works in my test project.

mbraak commented

The fix is included the latest release

mbraak commented

There is still an issue when the jquery versions are different. I'm working on a pr.

mbraak commented

The issue with the different jquery versions is fixed in version 1.7.3