简体   繁体   English

如何在不每次运行build的情况下将webpack用于开发Angular2 /打字稿?

[英]How to use webpack for development Angular2 / typescript without running build each time?

I am using ASP.Net Core, Angular2 and Typescript and connected all together with webpack using the tutorial from Angular2 team here . 我使用ASP.Net核心,Angular2和打字稿,并使用从Angular2队教程,所有的WebPack一起连接在这里 That all seems to work but now I need to build each time I change a file. 一切似乎都正常,但是现在每次更改文件时我都需要构建。

Original tutorial uses system.js and that loads tons of files of course, but I just use static file middleware and no build is required for development. 原始教程使用system.js,当然会加载大量文件,但是我只使用静态文件中间件,因此开发不需要构建。 That is very convinient, but I cannot figure out how to do the same with webpack. 这非常方便,但是我无法弄清楚如何使用webpack进行同样的操作。 It seems that webpack can only bundle everything together without an option to just load everything separately so I need to run the build each time. 似乎webpack只能将所有内容捆绑在一起,而不能单独加载所有内容,因此我需要每次都运行构建。

Is it possible to do something so that webpack "expands" the bundle in some easy way? 是否可以做一些事情,使webpack以某种简单的方式“扩展”捆绑包?

PS I would like not to use webpack dev server and some auto-build on save and so on since the complexity is rather high alredy. PS我不希望使用webpack开发服务器以及一些在保存时自动构建等功能,因为复杂性很高。 So ideal solution is that I have bundles for production but direct code loaded for development like in good old days with standard mvc bundling. 因此,理想的解决方案是我拥有用于​​生产的捆绑包,但直接加载了用于开发的代码,就像过去使用标准mvc捆绑的好时机一样。

Really, the best way would be to use webpack dev server. 确实,最好的方法是使用webpack开发服务器。 There's really not much setup involved, it's just a different command you run instead of webpack: 实际上并没有太多的设置,只是您运行的另一个命令而不是webpack:

npm install webpack-dev-server
webpack-dev-server webpack.config.js

Then you just point script sources to http://localhost:8080/webpack-dev-server/your-bundle-name.js" in your application ` tags. 然后,您只需将脚本源指向http://localhost:8080/webpack-dev-server/your-bundle-name.js" in your application `标签中的http://localhost:8080/webpack-dev-server/your-bundle-name.js" in your application

This is by far the best option as you get instant incremental recompile and live-reload. 到目前为止,这是最佳选择,因为您可以立即进行增量重新编译和实时重载。

While I would strongly encourage you to use webpack-dev-server you can also just use plain webpack in watch mode: 虽然我强烈建议您使用webpack-dev-server但也可以在监视模式下使用普通的webpack:

webpack ---watch 

There is no way to "expand the bundle" (and really no need to). 没有办法“扩展捆绑包”(并且实际上没有必要)。 In all likelyhood you are using webapack for more than just bundling, so you'd still require to re-build if you change a typescript file, for example. 在所有情况下,您都在使用webapack进行捆绑销售,而不仅仅是捆绑销售,因此,例如,如果您更改打字稿文件,则仍然需要重新构建。 Webpack dev server or webpack in watch mode do very quick incremental compiles, and most people will just leave them running while developing. 监视模式下的Webpack开发服务器或webpack可以非常快速地进行增量编译,并且大多数人在开发过程中只会让它们运行。

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

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