Z
Z
zeni1agent2021-06-26 16:19:03
JavaScript
zeni1agent, 2021-06-26 16:19:03

Is it possible to choose what to load inside a module?

I want to choose which script to load

if(true){
import { OrbitControls } from './s/OrbitControls.js';
}

but I get
SyntaxError: Unexpected token '{'

How can I check which scripts I want to load?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2021-06-26
@zeni1agent

It is forbidden. The import statement is only allowed at the top level, outside of conditions and functions.
There is a dynamic import.
https://learn.javascript.ru/modules-dynamic-imports
https://developer.mozilla.org/ru/docs/Web/JavaScri...
https://habr.com/ru/post/455200/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question