简体   繁体   English

在浏览器之外处理Webpack

[英]Dealing with Webpack outside of the browser

I love a lot about Webpack and there's no shortage of blog posts singing its praises so I'll just reiterate that what it does is incredible for generating a client side js bundle along with ancillary files like css, images, markdown, etc. Now on to the problems… 我非常喜欢Webpack,并且不乏博客文章赞美它,所以我只想重申一下,它对于生成客户端js捆绑以及诸如css,images,markdown等辅助文件的功能是不可思议的。解决问题...

Using require for non-js files has been a major hassle to get around outside of the browser-bundle context. 使用non-js文件的require是避免浏览器绑定上下文之外的主要麻烦。 I'll just talk about two big ones I've faced. 我只说说我遇到的两个大问题。

  1. Rendering react components server-side that require non-js files. 渲染require非js文件的服务器端组件。
  2. Running integration tests on express middleware that require files that in-turn require other non-js files. require文件的快速中间件上运行集成测试,而文件又require其他非js文件。 The middleware itself is fine. 中间件本身很好。

I've gotten around the first issue using Webpack Isomorphic Tools which seems like an ok workaround. 我已经使用Webpack同构工具解决了第一个问题,这似乎是一个不错的解决方法。 I was doing a second server side Webpack bundle but I didn't like the dev-server/rebuild setup I had. 我正在做第二个服务器端Webpack捆绑包,但是我不喜欢我的dev-server / rebuild设置。 I'm still not sure how best to handle the mocha issue. 我仍然不确定如何最好地处理摩卡咖啡问题。 Tests I have that run in a browser are fine using Karma and karma-webpack. 使用Karma和karma-webpack可以在浏览器中运行测试。 But I want my middleware test to run on Node. 但是我希望我的中间件测试能够在Node上运行。

Once I decided to require a non-js file I really tied my hands on how I can work with that file. 一旦我决定需要一个非js文件,我就真的将我的手放在如何使用该文件上。 I'm really curious what others are doing? 我真的很好奇别人在做什么?

I tried crafting a setup with both server side and client side Webpack builds. 我尝试使用服务器端和客户端Webpack构建来制作安装程序。 https://github.com/halt-hammerzeit/webpack-react-redux-isomorphic-render-example Seems to work ok, still it may be not the best solution. https://github.com/halt-hammerzeit/webpack-react-redux-isomorphic-render-example似乎可以正常工作,但它可能不是最佳解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM