Also in default index page I put a tag <script> hello() </script> on body page. I expected that string Ola will printed in console but a error saying that this function not exists is raised.
So I put import in app.js like this: import {hello} from "test.js" , but still raising error. What I`m doing wrong?
This not works… I’m testing with browser console , when I run hello() returns Uncaught ReferenceError. But if call hello() from inside app.js then I can see "Ola" in output console.
Ok, put that file inside your static folder and then inside your_app_web.ex put your filename inside plug Plug.Static , on only: ~w(css fonts images favicon.ico robots.txt test.js) and hopefully it will work
This is expected. Code bundled with webpack is not available in the global namespace.
If you want to be able to call your code from the console or other included scripts you should make it available exxplicitly with window.hello = hello.
Also I think there is a webpack config option that allows to define the name of the variable that is defined in window that will reference the export default value of your main file.