国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > JS > 正文

websocket4.0+typescript 實現(xiàn)熱更新的方法

2024-05-06 16:54:10
字體:
供稿:網(wǎng)友

最近搞了一個webpack4+typescript的開發(fā)環(huán)境,折騰了很久現(xiàn)在記錄一下。。。。

本身環(huán)境比較好搞,但是熱更新是個麻煩事兒

本環(huán)境是基于webpack-dev-server搭建的

 output: {  publicPath: '/dist',  path: path.resolve(__dirname, 'dist'),  filename: 'ljax.bundle.js',  hotUpdateChunkFilename: 'hot/hot-update.js',  hotUpdateMainFilename: 'hot/hot-update.json' },

publicPath是必須的字段,不添加HRM就沒有效果

在熱更新的時候會出現(xiàn)很多hot-update.js和hot-update.json的細碎文件

使用hotUpdateChunkFilename和hotUpdateMainFilename指定他們只生成一個文件,目前沒有找到不生成這兩個文件的辦法,如果哪位大佬知道的話請告知。

plugins: [  new HtmlWebpackPlugin({   title: '模塊熱替換',   template: './public/index.html'  }),  new webpack.HotModuleReplacementPlugin(),  // 啟動輸出清理  new FriendlyErrorsWebpackPlugin({   compilationSuccessInfo: {    messages: [`You application is running here ${HTTPS ? 'https' : 'http'}://${HOST}:${PORT}`],    // notes: ['Some additional notes to be displayed upon successful compilation'],    clearConsole: true   },  }) ],

HotModuleReplacementPlugin是熱更新必不可少的插件

 contentBase: __dirname,  quiet: true,  compress: true,  port: PORT,  host: HOST,  https: HTTPS,  // hot: true,  // hotOnly: true,  // inline: true,  open: true,  overlay: true,  openPage: './dist/index.html'

最坑的地方來了,我一開始是加上可hot和hotOnly字段的,但是不管是兩個都加還是單獨使用任何一個,HRM都沒有效果。。。。

最后發(fā)現(xiàn)兩個都不實用就可以。。。。。媽耶,我還是從官網(wǎng)看的這個配置。

到現(xiàn)在也不是很了解是怎么回事。。

最后,貼一下完整的配置吧

webpack.config.js

const path = require('path')const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')const webpack = require('webpack')const HtmlWebpackPlugin = require('html-webpack-plugin')const HOST = 'localhost'const PORT = 8080const HTTPS = falsemodule.exports = { mode: 'development', context: __dirname, entry: {  app: './src/index.ts' }, output: {  publicPath: '/dist',  path: path.resolve(__dirname, 'dist'),  filename: 'ljax.bundle.js',  hotUpdateChunkFilename: 'hot/hot-update.js',  hotUpdateMainFilename: 'hot/hot-update.json' }, module: {  rules: [   { test: //.ts/, use: 'ts-loader', exclude: /node_modules/ }  ] }, resolve: {  extensions: ['.ts', '.js'] }, plugins: [  new HtmlWebpackPlugin({   title: '模塊熱替換',   template: './public/index.html'  }),  new webpack.HotModuleReplacementPlugin(),  // 啟動輸出清理  new FriendlyErrorsWebpackPlugin({   compilationSuccessInfo: {    messages: [`You application is running here ${HTTPS ? 'https' : 'http'}://${HOST}:${PORT}`],    // notes: ['Some additional notes to be displayed upon successful compilation'],    clearConsole: true   },  }) ], devServer: {  contentBase: __dirname,  quiet: true,  compress: true,  port: PORT,  host: HOST,  https: HTTPS,  // hot: true,  // hotOnly: true,  // inline: true,  open: true,  overlay: true,  openPage: './dist/index.html' }}

package.json

{ "name": "ljax", "version": "1.0.0", "description": "", "main": "index.js", "scripts": {  "test": "echo /"Error: no test specified/" && exit 1",  "watch": "webpack -w",  "dev-server": "webpack-dev-server",  "serve": "start yarn dev-server && yarn watch" }, "author": "", "license": "ISC", "dependencies": {  "friendly-errors-webpack-plugin": "^1.7.0",  "html-webpack-plugin": "^3.2.0",  "ts-loader": "^6.0.4",  "typescript": "^3.5.3",  "webpack": "^4.39.1",  "webpack-dev-server": "^3.7.2" }, "devDependencies": {  "webpack-cli": "^3.3.6" }}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網(wǎng)。


注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 华亭县| 垣曲县| 杭州市| 博罗县| 黎平县| 嵊泗县| 乐陵市| 正宁县| 南雄市| 上饶市| 叶城县| 乡宁县| 三明市| 革吉县| 铁岭市| 南木林县| 东丽区| 怀宁县| 收藏| 盘山县| 唐山市| 湘潭市| 徐汇区| 江油市| 高安市| 金湖县| 平和县| 神池县| 梨树县| 礼泉县| 虹口区| 博野县| 罗田县| 昌江| 平舆县| 高州市| 太仓市| 尼木县| 陕西省| 龙州县| 独山县|