Skip to content

Latest commit

 

History

History

005-how-to-dynamically-import-a-module

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
title c3p hasDemo deprecated tags date
How to dynamically import a module in Construct 3
how-to-dynamically-import-a-module-20.07.12.c3p
true
true
javascript
created updated
2020-07-11 12:00
2020-07-11 12:00

How to dynamically import a module in Construct 3

let wiki;
let c3_colorjs;

runOnStartup(async runtime =>
{
	wiki = await loadModule(runtime, 'wiki.js');
	c3_colorjs = await loadModuleURL(runtime, 'https://c3demo.stranianelli.com/javascript/000-snippets/c3_colors_helper.js');
});


async function loadModule(runtime, name) {
	const isPreview = window.location.href === `https://preview.construct.net/local/index.html`;
	const file = isPreview ? await runtime.assets.getProjectFileUrl(name) : `../${name}`;
    const mod = await import(file);
	return mod;
}

async function loadModuleURL(runtime, name) {
    const mod = await import(name);
	return mod;
}