How can I create a link for the imported modules so that I don't have to modify the new imports every time?

Hi,

I would like to put in one place all my imported modules so that when I create a new class player.js I automatically import all these modules. The goal is that if I add an import I only have to specify it once…there should be some kind of link to these imported modules.

import {
	can_init,
	can_add_element,
	can_add_ghost,
	can_add_physic,
	can_animate_instances,
	can_animate_physic,
	can_check_collisions,
	can_hide_eye,
	can_move,
	can_move_lateral,
	can_ressurect,
	can_wake_up,
	create_box_with_rounded_edges,
} from '../classes/can_action.js'

example, if i add a another module “can_start”:

I don’t have to add it in player.js and enemy.js since if I manage to have a link to these imported modules, I have to do it only once and not for each class.

import {
	can_init,
	can_add_element,
	can_add_ghost,
	can_add_physic,
	can_animate_instances,
	can_animate_physic,
	can_check_collisions,
	can_hide_eye,
	can_move,
	can_move_lateral,
	can_ressurect,
	can_wake_up,
	create_box_with_rounded_edges,
        can_start,
} from '../classes/can_action.js'

Is it possible simply ?

you could use

import * as CANS from "../classes/can_action.js";

but then you’d need to use your variables, functions or classes something like

const CAN_START = CANS.can_start
const CAN_START = CANS.can_start()
const CAN_START = new CANS.can_start()

It depends on whether you are exporting variables, functions or classes.

Hi @seanwasere,

Thanks, i know this feature but I need to add a variable in front of each of my calls…(I don’t like this very much :slight_smile: )

Isn’t there a way to call all the imports in a .js file and then link to this page?

Have you looked at the extends keyword.

Here are some example usages. Maybe one of these examples in the search results is similar to what you are trying to achieve.

Threejs : Search · extends · GitHub

R3F : Search · extends · GitHub