Comments (6)
Did you fixed the issue?
from starter-bootstrap.
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?
from starter-bootstrap.
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 array( 'jquery' )
parameter. It's strongly advised to import the jQuery version that comes with WordPress:
https://them.es/support/2019/07/06/goodbye-jquery/
https://them.es/support/2021/05/10/them-es-starter-v3-released/
Hope this helps?
from starter-bootstrap.
Javascripts should be enqueued via functions.php (wp_enqueue_script) only.
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:
Uncaught SyntaxError: Cannot use import statement outside a module
in my functions.php file
wp_enqueue_script( 'extras', get_template_directory_uri() . '/assets/Extras.js', array('jquery'), $theme_version, true );
in my Extras.js under /assets
import axios from "../axios"
class Search {
constructor(){
alert("I am a search.");
}
}
const mysearch = new Search();
from starter-bootstrap.
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. main: [ './main.js', './Extras.js' ],
This will incorporate the "Extras" code in main.js
and is documented here https://webpack.js.org/concepts/entry-points
from starter-bootstrap.
Axios doesn't seem to be ready for ESM yet (axios/axios#4209) but for now you can try an alternative package (unofficial):
axios/axios#1879 (comment)
...or import the JS source directly:
import '[DIRECTORY_WHERE_AXIOS_IS_LOCATED]/dist/axios.min.js';
But since this issue is not related to the code in this repo it will be closed. Good luck!
from starter-bootstrap.
Related Issues (20)
- New user of this wonderful starter theme and upgrade, add zip package creation HOT 1
- Gutenberg Block Editor not adding styles. HOT 1
- Error in plugin "webpack-stream" HOT 1
- Latency with Browser reload HOT 1
- Why both gulp and webpack ?? HOT 1
- the_content(); does not work anywhere in template
- Site brand logo? (Navbar) HOT 1
- Please show a woocommerce sample HOT 1
- WordPress 6.01 Breaks Menu HOT 2
- Deprecated dependencies? HOT 2
- wordpresscom include HOT 1
- Use of content width HOT 1
- Inconsistent use of curly braces for implications HOT 1
- Critical Error Caused by Footer HOT 1
- Color modes not work HOT 2
- Css HOT 4
- Package vulnerabilities HOT 2
- Problem with the webpack config HOT 11
- Unable to be override files via child themes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from starter-bootstrap.