If an npm package ships with multiple dist folders, how do I know which one is used when my App is built?

Viewed 134

I am using an npm package (aurelia-google-maps) in my application. The package ships with AMD, System, CommonJS, Native Modules, and ES2015 dist folders like this:

/node_modules/
    /aurelia-google-maps/
        /dist/
            /amd
            /system
            /native-modules
            /es2015
            /commonjs

In my typescript app I am simply importing all the classes and functions as:

import {Configure} from "aurelia-google-maps"

Is there a way that I can find out which distribution is used when I build my application?

2 Answers

I don't think you can determine it without the help of your build tool. It can be done in 2 steps:

  • using type of to check the availability of a variable in runtime code:
const distType = typeof DIST_TYPE !== 'undefined' ? DIST_TYPE : void 0;
  • configure the build tool to replace DIST_TYPE with the distribution target

And then you can use it in normal code, via distType variable.


For typescript, you just need an extra declaration

declare const DIST_TYPE: string | undefined;

I have figured it out. It seems like Aurelia automatically registers it's own plugin called DistPlugin that resolves dependencies using the native-modules folder. See this wiki for an explanation on how to change this behaviour.

Related