Create-react-app: Webpack ProvidePlugin

Created on 10 Apr 2018  路  15Comments  路  Source: facebook/create-react-app

Hi, I'm wondering if create-react-app supports ProvidePlugin.I'm afraid that the answer for this will just be "eject"

question

Most helpful comment

@fparga, @avilang You can manually push this dependencies to the window. Something like this:

// globals.js
import React from 'react';
import ReactDOM from 'react-dom';
import jquery from 'jquery';

window.React = React;
window.ReactDOM = ReactDOM;
window.jQuery = jquery;
window.jquery = jquery;
window.$ = jquery;
// index.js cra entry
import './globals'; // <-- first line
...

All 15 comments

No, it doesn鈥檛. Why do you need it?

@gaearon I think automatically load modules is a good ideas instead of having to import or require them everywhere

@gaearon What鈥檚 the best way to use libraries that need to have some globally available dependencies then?

For example, golden-layout needs to have react, react-dom and jquery.

@fparga, @avilang You can manually push this dependencies to the window. Something like this:

// globals.js
import React from 'react';
import ReactDOM from 'react-dom';
import jquery from 'jquery';

window.React = React;
window.ReactDOM = ReactDOM;
window.jQuery = jquery;
window.jquery = jquery;
window.$ = jquery;
// index.js cra entry
import './globals'; // <-- first line
...

@strayiker I know but I don't think this is a good solution

The solution explained by @strayiker is much better than using provide plugin.

No, it doesn鈥檛. Why do you need it?

For example: react-trumbowyg this componet need set up jquery fot this way

For example: react-trumbowyg this componet need set up jquery fot this way

It should still work if you do this: https://github.com/facebook/create-react-app/issues/4281#issuecomment-381119612

For example: react-trumbowyg this componet need set up jquery fot this way

It should still work if you do this: #4281 (comment)

With your permission, I will do 馃憤馃徎

Let us know if it doesn't work out and maybe we can help more.

Let us know if it doesn't work out and maybe we can help more.

It does not work in my case :(

@erikaperugachi Can you provide a complete example project that shows it not working?

You can see it works fine here: https://codesandbox.io/s/y3x48qv3kj

Feel free to download the project (there's a button in CodeSandbox on the top panel) and try it.

You can see it works fine here: https://codesandbox.io/s/y3x48qv3kj

Feel free to download the project (there's a button in CodeSandbox on the top panel) and try it.

Thank you, my bad was put this import "./globals"; after import Trumbowyg from 'react-trumbowyg'

You are awesome! thank for your time

@fparga, @avilang You can manually push this dependencies to the window. Something like this:

// globals.js
import React from 'react';
import ReactDOM from 'react-dom';
import jquery from 'jquery';

window.React = React;
window.ReactDOM = ReactDOM;
window.jQuery = jquery;
window.jquery = jquery;
window.$ = jquery;
// index.js cra entry
import './globals'; // <-- first line
...

thank you, i did global only $ and it didnt work

Was this page helpful?
0 / 5 - 0 ratings