R
R
retyui2017-02-28 15:44:36
webpack
retyui, 2017-02-28 15:44:36

What is the correct way to load polyfill for Promise in webpack 2?

Lazy man's path:
webpack.config.js

{
     entry: ['core-js/fn/promise', './main.js']
};

Is there a universal way to load a promise on demand:
if('Promise' in windoW){
    // main.js
  }else{
    // Promise polyfill + 
    // main.js	
}

- Do two assemblies and load the right one?
- Make a custom script loader according to the condition of the polyfill in its download cobec to load the main file?
What solutions do you have?
The main condition is if there is no promise, then we will load its polyfill.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
amokrushin, 2017-02-28
@amokrushin

For example like this:

<script>
    window.Promise || document.write('<script src="https://unpkg.com/[email protected]/dist/es6-promise.auto.min.js"><\/script>');
</script>

put in head

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question