-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I import jQuery and other js files to main.js? #12
Comments
Did you fixed the issue? |
No, I'm still looking for an answer. Right now, I'm putting my js scripts in the footer. Do you know any other solutions to this? |
Javascripts should be enqueued via functions.php (wp_enqueue_script) only. And since jQuery has been dropped in the latest version of the Starter Theme it needs to be activated via the Hope this helps? |
It means that every additional js will not be bundled in main.js right? So I will have additional js loaded on my site. As for the jQuery, it's ok, I can convert my script to vanilla JS but I still can't import. After I have enqueued my extra js script, inside that file I need to import axios but it's giving me an error:
in my functions.php file in my Extras.js under /assets
|
Did you reference "Extras.js" in the Webpack config? https://github.com/them-es/themes-starter-bootstrap/blob/main/webpack.config.js#L7 i.e. This will incorporate the "Extras" code in |
Axios doesn't seem to be ready for ESM yet (axios/axios#4209) but for now you can try an alternative package (unofficial): ...or import the JS source directly: But since this issue is not related to the code in this repo it will be closed. Good luck! |
I'm trying to organize my js files on main.js. As of now, this is how my main.js looks like:
In MyNotes.js is where I import jquery and it looks like this
But every time I run npm, I'm having this problem:
If I put my other js files inside main.js (for example the Search.js and Defaul.js which is the default js files from the install), it works properly but I'm still having trouble importing jquery inside main.js. I tried
import $ from 'jQuery'
also but also doesn't work. I can see that jquery is installed under node_modules folder but after failed attempts in importing it, I rannpm install jquery
but was still the same error.What am I doing wrong?
The text was updated successfully, but these errors were encountered: