webpack热重载毫无任何反应
问题分析:页面正常加载,npm run dev也无任何报错,控制台HMR完全没有,我记得websocket应该有个sockjs.node用来热更新的也没有。。。什么都没有
项目git地址 :git@github.com:liangyuqi/awesome-image.git
部分关键代码
- package.json
{
"name": "awesome-image",
"version": "1.0.0",
"description": "init",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack-dev-server --config ./webpack-dev.config.js --content-base ./example --color --environment NODE_ENV:development",
"dev:liangyuqi": "webpack-dev-server --config ./webpack-dev.config.js --host 10.232.8.48 --port 8086 --progress",
"build": "webpack --config ./webpack-build.config.js --environment NODE_ENV:production"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/jest": "^23.3.13",
"@types/node": "^10.12.20",
"@types/tapable": "^1.0.4",
"@types/webpack": "^4.4.24",
"awesome-typescript-loader": "^5.2.1",
"html-webpack-plugin": "^3.2.0",
"immutable": "^4.0.0-rc.12",
"ts-loader": "^5.3.3",
"tslint": "^5.12.1",
"typescript": "^3.2.4",
"webpack": "^4.29.0",
"webpack-cli": "^3.2.1",
"webpack-dev-server": "^3.1.14"
},
"repository": {
"type": "git",
"url": "git+https://github.com/liangyuqi/awesome-image.git"
},
"bugs": {
"url": "https://github.com/liangyuqi/awesome-image/issues"
},
"homepage": "https://github.com/liangyuqi/awesome-image#readme",
"dependencies": {
"@types/lodash": "^4.14.120"
}
}
- webpack-dev.config.js
const path = require('path')
const join = path.join
const resolve = path.resolve
const {
camelCase
} = require('lodash')
const webpack = require('webpack')
const {
TsConfigPathsPlugin,
CheckerPlugin
} = require('awesome-typescript-loader')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const env = process && process.env && process.env.NODE_ENV
const serverPort = process.env.npm_package_config_devPort || 8084
const dev = !(env && env === 'production')
/**
* Update this variable if you change your library name
*/
const libraryName = 'awesome-image'
const plugins = [
new CheckerPlugin(),
new TsConfigPathsPlugin(),
new HtmlWebpackPlugin({
inject: true,
title: libraryName,
filename: 'index.html',
template: join(__dirname, 'example/index.html'),
hash: true,
chunks: ['common', 'index']
})
]
let entry = [
// 'react-hot-loader/patch',
`webpack-dev-server/client?http://localhost:${serverPort}`,
// 'webpack-hot-middleware/client?reload=true',
// bundle the client for webpack-dev-servers and connect to the provided endpoint
'webpack/hot/only-dev-server',
// bundle the client for hot reloading
// `./src/${libraryName}.ts`
__dirname + `/example/index.ts`
]
if (dev === false) {
} else {
plugins.push(new webpack.HotModuleReplacementPlugin())
}
// plugins.push(new TsConfigPathsPlugin({configFile: "example/tsconfig.json"}))
module.exports = {
mode: 'development',
entry: {
index: entry
},
// Currently cheap-module-source-map is broken https://github.com/webpack/webpack/issues/4176
devtool: 'source-map',
output: {
path: join(__dirname, 'dist'),
libraryTarget: 'umd',
library: camelCase(libraryName),
filename: `${libraryName}.js`
},
resolve: {
extensions: ['.ts', '.js']
},
externals: {
"createjs": "createjs"
},
module: {
rules: [{
test: /\.ts$/,
use: [{
loader: 'ts-loader'
}]
},
{
test: /\.scss$/,
use: [ 'style-loader', 'css-loader', 'sass-loader' ]
}]
},
plugins: plugins,
devServer: {
hot: true,
contentBase: resolve(__dirname, 'example'),
port: serverPort,
publicPath: '/'
}
}
- 文件结构:
- 控制台输出
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
同热重载不管用,过来问一哈有解决方案了吗
你的
example\index.html
中的这段注释删除,或者放到后面去吧。html-wabpack-plugin
的inject
的原理是通过正则匹配template
中第一个</body>
或者</html>
作为插入位置。你的
chunks
被插入在这里了。