ami icon indicating copy to clipboard operation
ami copied to clipboard

AMD Support

Open edsilv opened this issue 6 years ago • 2 comments

Description

Unable to load AMI using require.js (AMD).

Live Demo

https://github.com/edsilv/ami-amd-test

Steps to Reproduce

npm start

Expected Results

Logs AMI object.

Actual Results

Logs undefined here: https://github.com/edsilv/ami-amd-test/blob/master/index.html#L17

Browsers Affected

  • [x ] All
  • [ ] Chrome
  • [ ] Firefox
  • [ ] Edge
  • [ ] Safari 9
  • [ ] Safari 8
  • [ ] IE 11

Versions

  • AMI: v0.27.0

edsilv avatar Jan 04 '19 13:01 edsilv

I forgot to mention above that window.AMI also isn't available.

This seems to have helped: https://stackoverflow.com/questions/45676589/typescript-module-webpack-requirejs#comment78312146_45676960

I tried using libraryTarget: 'var' instead of umd, which appears to have solved loading with requirejs. The window.AMI object is available on console.log(d) - but d is still undefined unless I add a shim:

requirejs.config({
    shim: {
        'lib/ami': { 
            exports: "AMI"
        }
    }
});

Have you considered building multiple distributions for commonjs, es6 modules, UMD, and var exports?

I've been experimenting with this approach in my "manifesto" project (webpack branch), which uses TypeScript in a similar way to AMI.

It uses tsc to build commonjs and es6 modules, then webpack to generate a UMD module and var export.

edsilv avatar Jan 04 '19 17:01 edsilv

@edsilv yes what you suggest would be ideal but we just didn't have time to look into :( PRs welcome :)

NicolasRannou avatar Jan 07 '19 12:01 NicolasRannou