Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

前端页面热更新无效! #11

Closed
Stanlous opened this issue Apr 21, 2018 · 5 comments
Closed

前端页面热更新无效! #11

Stanlous opened this issue Apr 21, 2018 · 5 comments

Comments

@Stanlous
Copy link

Stanlous commented Apr 21, 2018

单独使用egg-webpack,修改前端页面文件,webpack自动编译了,但是没有热更新,前端页面没有自动更新修改。
情况一:只使用koa-webpack-dev-middleware和koa-webpack-hot-middleware,修改前端页面文件,webpack自动编译了,而且自动热更新前端页面。热更新有效!
egg里的app.js内容如下:

const webpack = require('webpack')
const webpackDevMiddleware = require('koa-webpack-dev-middleware')
const webpacHotMiddleware = require('koa-webpack-hot-middleware')
const IS_PRODUCTION = process.env.NODE_ENV == 'production'
const devConfig = require('../config/webpack/webpack.dev.js')
const prodConfig = require('../config/webpack/webpack.prod.js')
const config = IS_PRODUCTION ? prodConfig : devConfig
const compiler = webpack(config)

module.exports = app => {
  app.beforeStart(async () => {
    app.use(webpackDevMiddleware(compiler, {
      publicPath: config.output.publicPath
    }))
    app.use(webpacHotMiddleware(compiler))
  })
}

情况二:删除上面的app.js,只启用egg-webpack(按照README.md里的说明),修改了前端页面文件,webpack自动编译了,但没有热更新前端页面。热更新无效!
{app_root}/config/config.default.js

exports.webpack = {
  webpackConfigList: [require('../../config/webpack/webpack.dev.js')]
}
@muzi131313
Copy link

同问

@hubcarl
Copy link
Collaborator

hubcarl commented Jul 9, 2018

@Stanlous @muzi131313 egg-webpack 需要增加如下配置

// ${root}/config/config.local.js
config.webpack = {
  hot: true
}

@fakership
Copy link

@muzi131313 你的改了hot: true就ok了么,我这边貌似没启效果,是因为webapck4么

@hubcarl
Copy link
Collaborator

hubcarl commented Feb 12, 2019

单独使用 egg-webpack 时,需要在webpack 的 entry 加上 https://github.com/webpack-contrib/webpack-hot-middleware 配置 webpack-hot-middleware/client

@keenwon
Copy link

keenwon commented Feb 14, 2019

我写了个示例,有需要的朋友可以参考:https://github.com/keenwon/Egg-Webpack-Starter

@hubcarl hubcarl closed this as completed Feb 15, 2019
@hubcarl hubcarl pinned this issue Feb 15, 2019
@hubcarl hubcarl unpinned this issue Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants