Integrating into a Webpack 2 project
See original GitHub issueHi @shockey
Let me first summarize our earlier conversation about the issues i ran into bundling swagger-ui into a webpack-2 project.
- did 
npm install swagger-ui - I tried to do the obvious 
import Swagger from 'swagger-ui'- results in build error:
 
 
ERROR in ./~/yaml-js/lib/yaml.js
Module not found: Error: Can't resolve 'fs' in '/project-path/node_modules/yaml-js/lib'
- I added a webpack stub for node/fs, like what’s in swagger-ui’s own webpack config:
 
node: {
    fs: 'empty'
  },
- 
- this resulted in the build succeeding, but my app wouldn’t load, due to the error:
Uncaught Error: Cannot find module "." - and a bunch of warnings showed up in the console:
 
 - this resulted in the build succeeding, but my app wouldn’t load, due to the error:
 
./~/yaml-js/lib/yaml.js
require.extensions is not supported by webpack. Use a loader instead.
- 
- this is because yaml-js uses require.extensions to register itself as a yaml loader for node.js’s require, which is different from webpack’s.
 
 - 
i used
webpack.ProvidePluginto stub require.extensions to null: 
new webpack.ProvidePlugin({
  'require.extensions': null
})
- 
- this cleared the warnings, but the “Cannot find module” error remained.
 - i was not able to find a way to fix that error.
 
 
so what ended up working for me is simply using the swagger-ui-dist package.
import SwaggerUI, { presets } from 'swagger-ui-dist/swagger-ui-bundle';
I used swagger-ui-bundle, the full dist file with all dependencies loaded, because in that case the yaml-js dependency was already resolved by swagger’s webpack 1 build.
I’d love to help get a true webpack 2 build working if possible, given the limitations of yaml-js, but for now I’m satisfied and this seems to be working fine.
Issue Analytics
- State:
 - Created 6 years ago
 - Reactions:5
 - Comments:7 (4 by maintainers)
 
Top Results From Across the Web
Getting Started - webpack
Webpack is used to compile JavaScript modules. Once installed, you can interact with webpack either from its CLI or API.
Read more >Getting Started With Webpack - Smashing Magazine
Let's take a deep dive into what webpack is and how to use it in your ... you can also use webpack in...
Read more >Using webpack Build System in Existing Codebases
Enter webpack. Our goal was to improve the speed and maintainability of the build process. A stretch goal was to incorporate the ability...
Read more >c# - How to integrate WebPack in a VisualStudio solution with ...
In a VisualStudio solution I have several (perhaps a lot of) projects. Now I want to add some web pages with React and...
Read more >Setting up Webpack for your Project | by Imran Sayed - Medium
@babel/core is babel compiler core. babel-loader helps transpile our js code into ES5 as not all browsers understand ES6. webpack-cli is a ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Awesome! Glad to hear it.
I’m going to close this since the problem is solved, feel free to open a ticket if you come across any other issues.
hey @shockey – just tried, and it works great!
replaced:
with