Here is the process in short: Compile the server code with webpack Use target: "node" or target: "async-node" Enabled HMR via --hot or HotModuleReplacementPlugin Use webpack/hot/poll or webpack/hot/signal The first polls the fs for updates (easy to use) The second listens for a process event to check for updates (you need a way to send the signal) Run the bundle with node. You can't use existing HMR loaders like react-hot-loader or style-loader because they make no sense in a server environment. Just add manuall replacement code at the correct location (i. e. accept request handler like in the example) You can't use the webpack-dev-server. It's a server which serves assets not a runner. Just run webpack --watch and node bundle.js. I would go the webpack/hot/poll?1000 route first. It's pretty easy to use and suitable for dev environments. For production (if you want to hot update your production server) the signal approach is better suited.
webpack = require 'webpack'
module.exports =
entry: [
'webpack/hot/poll?1000' # <-- 轮询更新内容的代码
'./src/main' # <-- 项目入口
]
target: 'node' # <-- 指明编译方式为 node
output:
path: 'build/'
filename: 'bundle.js' # <-- 编译结果的文件名
module:
loaders: [
{test: /\.coffee/, loader: 'coffee'}
]
plugins: [
new webpack.HotModuleReplacementPlugin() # <-- 照常启动 hot mode
]
resolve:
extensions: ['.js', '', '.coffee']
npm i webpack --watch & # <-- watch 模式 node build/bundle.js # <-- 运行的是打包结果的代码
exports.data = 'code 5' exports.printSelf = -> console.log 'doing 3'
lib = require './lib' console.log lib.data lib.printSelf() counter = 0 setInterval -> counter += 1 console.log counter , 2000 if module.hot module.hot.accept './lib', -> lib = require './lib' console.log lib.data lib.printSelf()
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有