Is there a way to use cdn files with responsejs using webpack?

I cannot configure pusher and fetch with npm in responsejs.Also, is there a way to use cdn inside your reaction code?

+6
source share
2 answers

Finally, I came up with a very simple answer

install npm pusher-js, es6-prom and isomorphic-fetch and import it as

var Pusher=require('pusher-js');
var fetch=require('isomorphic-fetch');
require('es6-promise').polyfill();
+1
source

You can use action-async- script -loader as a higher order component for this: https://github.com/leozdgao/react-async-script-loader

Just install it via npm:

npm install --save react-async-script-loader

, javascripts cdn, scriptLoader, URL-, .

import scriptLoader from 'react-async-script-loader';

// Your component code:
class YourComponent extends React.Component {
  render() {
    return <p>{
      this.props.isScriptLoadSucceed ? 'Scripts loaded.' : 'Loading...'
    }</p>;
  }
}

export default scriptLoader([
  'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js',
  'https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js'
])(YourComponent);

, , . ( ).

Decorator (ES7) , , HOC, README.

+1

Source: https://habr.com/ru/post/1016813/


All Articles