V
V
Vladimir2020-01-18 20:15:57
JavaScript
Vladimir, 2020-01-18 20:15:57

How to setup/use modules for typescript?

Good evening. I'm desperate!
Please tell me why this pops up, I'm already allergic to this inscription, I sat overnight yesterday and continue today ...
Code before compilation:
TS - file2:

//Initialize canvas
let canvas: any;
canvas = document.getElementById('scene');

//Initialize engine
let engine: any;
engine = new BABYLON.Engine(canvas, true);

let createScene: any;
createScene = function () { ... }

export default {
    createScene,
    engine
}

TS-file1:
import createScene from './modules/scene';
import engine from './modules/scene';

//Listener for document wait download
window.addEventListener('DOMContentLoaded', function() {

    //Initialize scene
    let firstScene: any;
    firstScene = createScene;

    engine.runRenderLoop(function() {
        firstScene.render();
    });

    window.addEventListener('resize', function() {
        engine.resize();
    });


});

5e233c286138b441949145.png
After compilation:
JS - file2:
exports["default"] = {
    createScene: createScene,
    engine: engine
};

js-file1:
"use strict";
exports.__esModule = true;
var scene_1 = require("./modules/scene");
var scene_2 = require("./modules/scene");
//Listener for document wait download
window.addEventListener('DOMContentLoaded', function () {
    //Initialize scene
    var firstScene;
    firstScene = scene_1["default"];
    scene_2["default"].runRenderLoop(function () {
        firstScene.render();
    });
    window.addEventListener('resize', function () {
        scene_2["default"].resize();
    });
});

I don't know what to do anymore, the code from the documentation doesn't work! Some cap!
Thanks a lot.
UPD: Removed commonjs from tsconfig, included webpack, tried several import / export variations, in short, the word is J

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
profesor08, 2020-01-18
@HistoryART

Well, make a normal webpack config so that it compiles into regular js. Or connect the script to the page as a module. Both are in the documentation. Study. If you're lazy, then...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question