I am coming from a c++ background, so javascript isn't a familiar language. However, I think I've figured out the basics of ES6 module importing/exporting. I'm having a bit of trouble figuring out the exporting syntax in the popular library gl-matrix https://github.com/toji/gl-matrix/blob/master/dist/gl-matrix.js .
I can include gl-matrix.js in my html file and it code works fine within my main.js script. However, I'm trying to use a linter (eslint) within vscode to help guide me in using proper javascript; eslint marks types like vec3 and mat4 as red because they're undefined. I've noticed my other modules are also marked red until I import them.
I've tried things like:
import {vec3} from 'gl-matrix.js';
and get the error Uncaught SyntaxError: The requested module 'gl-matrix.js' does not provide an export named 'vec3'
I've also tried import * as vl from 'gl-matrix.js'; and using vl.vec3, but no to luck either. It doesn't appear to me that gl-matrix.js is using the es6 module exporting, but I'm unsure. It is definitely using some export system.
Clicking the github link will take you to the entire gl-matrix.js for viewing, but here is some snippets of the type of exporting it is doing:
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 4);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setMatrixArrayType = setMatrixArrayType;
exports.toRadian = toRadian;
exports.equals = equals;
It then proceeds to define functions to use. As far as I can tell, WebPack is a way to compose many library js files into a single output file (gl-matrix.js in this case). Perhaps I'm wrong. This being the output file, it seems I should be about to import from it directly.
So really I have multiple questions. Is this some special syntax for ES6 modules? If so, how does one import it?
If it is not, how does one import properly? Is it likely eslint will be able to resolve the symbols and stop flagging them as undefined?
Any help on any of those questions is greatly appreciated.