node.js - 运行node项目时,怎么用webpack的热加载
巴扎黑
巴扎黑 2017-04-17 14:47:45
0
2
600

最近在项目中使用了webpack,感觉热加载这个特性很好用,但是由于是Node渲染,运行项目时要用node来跑,这个时候就用不了webpack的热加载了,因为webpack和node监听的是不同的端口。
目前的做法是用gulp监听静态资源,有变化时执行webpack,打包静态资源到dist目录,同时更新html里引用的静态资源地址,但是每次打包都要3秒左右,而且还要手动刷新浏览器,感觉开发效率很低。
想请教大家是怎么配置webpack做服务端渲染的项目的。

巴扎黑
巴扎黑

reply all(2)
Peter_Zhu

Have you seen this webpack-dev-middleware?

If you use express, you can integrate this middleware into your node application, it’s so high

Supplement:

There are examples on the website, as follows:

var webpackDevMiddleware = require("webpack-dev-middleware");
var webpack = require("webpack");

var compiler = webpack({
    // configuration
    output: { path: '/' }
});

app.use(webpackDevMiddleware(compiler, {
    // options
}));

If you express play enough 6, the above code is clear and easy to understand

洪涛

nodejs itself has hot loading, http://www.jianshu.com/p/ffc9...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template