Skip to content

Q: Remapping import path for browsers #19942

@greghornby

Description

@greghornby

TypeScript Version: 2.6.1

I am using a library called "gl-matrix" which I have the code and typings installed via npm.
npm install gl-matrix
npm install @types/gl-matrix

And it works fine in typescript with intellisense and all

root/src/index.js

import { mat4 } from "gl-matrix";
var aMatrix = mat4.create();

but the thing is, since browsers are now starting to natively support import statements, instead having to use require.js or something, I wanna do this natively, but I can't figure out how to get it to convert to the real import path of the javascript code for gl-matrix.
When it compiles I'd like it to point to root/node_modules/gl-matrix/dist/gl-matrix-min.js so I want it to emit this

import { mat4 } from "./../node_modules/gl-matrix/dist/gl-matrix-min.js";
var aMatrix = mat4.create();

I thought I could achieve this with the paths property of tsconfig, but apparently not.
tsconfig.json

{
  "compilerOptions": {
    "target": "es2015",
    "module": "es2015",
    "outDir": "./build",
    "noImplicitAny": true,
    "baseUrl": "./src",
    "paths": {
        "gl-matrix": ["./../node_modules/gl-matrix/dist/gl-matrix-min.js"]
    },
    "rootDirs": ["src"],
    "inlineSources": true
  },
  "exclude": [
      "node_modules",
      "./tools"
  ]
}

So my question is: is it possible to remap the import path when compiling to javascript, and if so how to do it.

My directory structure is:

root

src

index.ts

node_modules

gl-matrix....

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions