问题
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