The issues you are seeing might be https://github.com/webpack/webpack/issues/4258. As jQuery is included in the webpack bundle, it will not make $ available on window by default. One solution according to the issue is to add
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
],
Maybe that will help for jquery, but I have the problem with all my tested js files. For e.g. “tooltip.js”, I receive the error message: “ReferenceError: Tooltip is not defined”
@Route
@NpmPackage(value="tooltip-js", version = "3.0.0")
@JavaScript("tooltip-js/dist/tooltip-min.js")
public class MainView extends VerticalLayout {
public MainView(@Autowired MessageBean bean) {
Div div = new Div();
div.setClassName("my-tooltip");
div.setText("tooltip");
add(div);
UI.getCurrent().getPage().executeJs("new Tooltip({ el: document.body.querySelector('.my-tooltip')});");
}
}
If I check my Browser, tooltip.min.js, will be available, but I can’t use it.
(add a button and a div and css file) and call manually the tooltip.show() in the browser.
The render was not great (and not really a tooltip) but it worked and I think the library is working this way.
I need to get it run without a button. The Tooltip should appear after loading the page.
So the “tooltip-loader.js” solution is not working. If I check the Browser Console, I can’t see that “tooltip-min.js” was proper loaded.
@NpmPackage(value="tooltip-js", version = "3.0.0")
@JavaScript("./src/tooltip-loader.js")
public class MainView extends VerticalLayout {
public MainView(@Autowired MessageBean bean) {
Div div = new Div();
div.setClassName("my-tooltip");
div.setText("tooltip");
add(div);
UI.getCurrent().getPage().executeJs("var tooltip = new Tooltip({ "+
"el: document.body.querySelector('.my-tooltip'), "+
"title: 'test' "+
"});"+
"tooltip.show();");
}
}