From e31de0ddcc1ab51228eba05db18afa751aab1f02 Mon Sep 17 00:00:00 2001 From: Ryan Mark Date: Wed, 17 Apr 2019 15:15:56 -0700 Subject: [PATCH] Fix ie (#31) --- index.js | 30 +++++++++++++++++++++++++++++- package.json | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e7048a8..763709f 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,33 @@ 'use strict'; +const caniuse = require('caniuse-api') module.exports = { - name: require('./package').name + name: require('./package').name, + options: { + autoImport: { + alias: {} + } + }, + + chooseLibPhoneForTargets(targets = {}) { + let { browsers = [] } = targets; + let browserQuery = browsers.join(','); + if (caniuse.isSupported('es6-module', browserQuery)) { + return 'libphonenumber/index.es6.js'; + } + return 'libphonenumber-js/bundle/libphonenumber-js.min.js'; + }, + + included() { + this._super.included.apply(this, arguments); + + let findHost = this._findHost; + let app = findHost.call(this); + + this.app = app; + let targets = this.project.targets; + + this.options.autoImport.alias['libphonenumber-js'] = this.chooseLibPhoneForTargets(targets); + } + }; diff --git a/package.json b/package.json index 8bbd064..e5178f0 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "test:all": "ember try:each" }, "dependencies": { + "caniuse-api": "^3.0.0", "ember-auto-import": "^1.2.21", "ember-cli-babel": "^7.7.3", "libphonenumber-js": "~1.0.24"