How to access modules bundled from webpack outside bundles/chunks

你离开我真会死。 提交于 2019-12-23 07:38:53

问题


Let me first say that I have tried searching for an answer to this and haven't found anything that works or even hints to it being possible.

I recently moved from RequireJS configuration to rolling up with Webpack. In some places in our Groovy app we have have a script tag in a GSP that will access modules through RequireJS like so:

<html>
<body>
...

  <script>
      require([
          'jquery',
          'customModule'
      ], function($, customModule){
          // do something with jquery
          // ...
          // do something with customModule
      });
  </script>

</body>
</html>

I would need to be able to do the equivalent with Webpack for a few reasons, the most important is our ability to inject Javascript from our admin side to hotfix any production bugs without pushing a maintenance release.

Expecting I should be able to do something like this:

<html>
<body>
...

  <script>
      webpack_require([
          'jquery',
          'customModule'
      ], function($, customModule){
          // do something with jquery
          // ...
          // do something with customModule
      });
  </script>

</body>
</html>

If you know how to access Webpack bundles from the outside please share! Thanks

来源:https://stackoverflow.com/questions/35944067/how-to-access-modules-bundled-from-webpack-outside-bundles-chunks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!