admin管理员组文章数量:1122832
I am using Webpack for my website and in my src/js/
I have created three files ; app.js
, gsap-animations.js
and script.js
. My initial idea was to import my other custom js files into one single js file (in this case app.js
) just like this :
// -------------------------------------------------------------------
// ----- import node_modules scripts
// -------------------------------------------------------------------
import $ from "jquery";
import "bootstrap";
import gsap from "gsap";
import ScrollTrigger from "gsap/ScrollTrigger";
// -------------------------------------------------------------------
// ----- import custom scripts
// -------------------------------------------------------------------
import "./script.js";
import "./gsap-animations.js";
The first custom file, script.js
, loads up fine ; I am using jquery and have functions in there that I can see loaded up on my website. It's clearly doing things. Weirdly enough though, the second custom file, gsap-animations.js
, does not ever load. I was just testing around as I am pretty new with GSAP to begin with :
gsap.to('.test-img', {
ScrollTrigger: '.test-img',
y: 500,
duration: 3
});
This is supposed to make my image move on the y axis whenever it comes into the viewport.
After some fiddling around, I realized that if I move the import gsap from "gsap";
AND import scrollTrigger from "gsap/ScrollTrigger";
INTO gsap-animations.js
, IT WORKS. The question is WHY ?
Am I missing something ? Clearly, I use jquery in script.js
but have the import $ from "jquery";
in the app.js
file, not script.js
. I am able to use jquery in script.js
just fine though.
So why when it comes to GSAP I have to load it up in the specific file where I am using GSAP ? Am I just too dumb to notice something obvious here ?
Sorry, I know this is pretty newbie. I'm just confused and this is also extremely hard to explain so feel free to ask for clarification.
本文标签: javascriptHow to import multiple custom JS files into one main 39appjs39 fileStack Overflow
版权声明:本文标题:javascript - How to import multiple custom JS files into one main 'app.js' file? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736301448a1931181.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论