require
outside of bundle
WebPack expose This plugin may be usefull for high fidelity testing with selenium. Module by using selenium and keeping test code and source code aside.
Bundle will define parameter to window object, this will be the only global variable.
Wepack setup instuction example:
let ExposeRequirePlugin = ; /** * */moduleexports = // ... plugins: level: "dependency" // "all", "dependency", "application" pathPrefix: "example/simple/src" // in case if your source is not placed in root folder. // ...
As result you can use this code in browser:
The require
will be assigned as property to window. Each available bundle will assign his inner __webpack_require__
.
In example described above, there is bundle with name main
- see entry names, defauls is main
name -,
we are getting our main script that will bootstrap react application in given page.
To do:
- Develop moment for production use when one webpack bundle can require module from another bundle, but without exposing to
- Write tests.