简体   繁体   English

使用webpack的捆绑包构建是否与页面上的其他js隔离?

[英]Is a bundle build with webpack isolated from the other js on the page?

I have a very basic question about Webpack and Javascript . 我对WebpackJavascript有一个非常基本的问题。

If I want to bundle an application that is included other existing webpages, how can I be sure that the javascript code that I bundled and its dependencies do not collide with existing javascript code on these existing pages? 如果我想捆绑包含其他现有网页的应用程序,如何确定捆绑的javascript代码及其依赖项不会与这些现有页面上的javascript代码冲突?

Is this done automatically by Webpack ? 这是Webpack自动Webpack吗?

I wan't to provide a very small js component that can be included in arbitrary other sites for example via a tag, but want to make sure that existing code of these sites that will use this component is not affected in unforeseen ways. 我不想提供一个很小的js组件,例如可以通过一个标签将其包含在任意其他站点中,但要确保这些站点中将使用此组件的现有代码不会受到无法预料的影响。 How do i for example make sure that none of the dependencies that my component might have interfere with the global scope of the site? 例如,我如何确保组件的所有依赖项都不会干扰站点的全局范围?

Yes, you can use webpack bundle with other script at the same it. 是的,您可以将webpack包与其他脚本同时使用。 It doesn't use window object. 它不使用窗口对象。 Your code inside bundle will be isolated so you can use any dependencies. 包中的代码将被隔离,因此您可以使用任何依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM