Reputation: 1681
I am developing a WordPress plugin and it's heavily depends on javascript on admin side. Because it's a plugin and works on admin panel I have to be careful to prevent any conflict with other plugin's js codes, because it's like a common place, each plugin can load js libraries.
I am planning to use wordpress's default js scripts ( like jQuery, underscore, jquery-ui, etc. ) as external and bundle rest of the dependencies ( react, redux, numeral.js, etc. ) with webpack.
May this approach cause a conflict with another plugin's js code?
Maybe, if;
Can Webpack, browserify, or another tool or approach help me to prevent this conflict issues?
Upvotes: 1
Views: 2148
Reputation: 2652
Nothing you bundle via webpack, including the webpack runtime itself, is exposed globally. You could bundle your own jQuery (as an example, you're obviously using WordPress's) and use it safely alongside the existing one, and neither would have issues. You can even load multiple webpack builds without conflicts (they would be 'unaware' of each other). Webpack wraps all of its code in an immediately-invoked function, so everything is scoped local to that function. So unless you explicitly make something global, there is no risk of conflicts.
Upvotes: 1