How to test a Webpack bundle that has external dependencies?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 20:12:07

问题


I'm new to Webpacker and Rails in general. I recently moved to using Webpacker to bundle React components. Since part of the application still uses the asset pipeline, some dependencies are still stored in vendor/assets/javascript, and accessible as globals. The Webpack bundle declares those dependencies as external, and when serving the app, everything works great, as Rails serves the dependencies, which are then picked up by the bundle. Now I want to start testing the bundle using something like jsdom. I'm using mocha-webpack with the same config as in development.

How can I load the external dependencies in this case? If I understand correctly, the bundle builds fine, but when the tests run, the dependencies are not loaded.


回答1:


Consider using another webpack.config.js just for the test build, e.g. create a webpack.config.test.js that does not use externals, but bundles all vendor files as npm dependencies.



来源:https://stackoverflow.com/questions/46655678/how-to-test-a-webpack-bundle-that-has-external-dependencies

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