Amol Chaudhari
Amol Chaudhari

Reputation: 68

EmberJs - unable to implement dynamic-import-polyfill

We are trying to implement dynamic-import-polyfill to import external file Ember compile time(build time).

Followed steps mentioned in https://github.com/GoogleChromeLabs/dynamic-import-polyfill

but got stuck when adding following lines of code in ember-cli-build.js.

following line of import works fine ,because with this I can successfully bring ember server up

import dynamicImportPolyfill from 'dynamic-import-polyfill';

but as soon as I am adding following lines ,ember server throws exception on start and stops

dynamicImportPolyfill.initialize({     modulePath: '/web-app', // Defaults to '.'     importFunctionName: '$$$import' // Defaults to 'import'   });

When checked in error logs found following error

stack: ReferenceError: location is not defined at Object.e.initialize (C:\code\Project-Chimps\source\web-app\node_modules\dynamic-import-polyfill\dist\dynamic-import-polyfill.umd.js:1:366)

tried lots of sites but no where I got the proper example:

while defining dynamicImportPolyfill.initialize({.... what should be the value for modulePath:

I did not understand following info mentioned for modulePath

modulePath string
A path for which all relative import URLs will resolve from.

Default Value: '.'

This should be an absolute path to the directory where your production modules are deployed (e.g. /public/). If given a relative path, it is resolve against the current page's URL.

Someone please help us with the example how I can use dynamic-import-polyfill with EmberJs

Upvotes: 0

Views: 355

Answers (1)

jrjohnson
jrjohnson

Reputation: 2459

There is no need to add this polyfill for your ember app. ember-auto-import already supports this feature after some additional configuration. Once you've installed and configured ember-auto-import you can dynamically import any NPM package and it will be loaded only when needed.

The step of adding and configuring ember-auto-import will be unnecessary very soon as Ember Octane Edition (set to be finalized in November 2019) will include this functionality by default in all apps.

Upvotes: 1

Related Questions