GVKun编程网logo

650 webpack DevServer和HMR:,,,,,,,,,,,

15

针对650webpackDevServer和HMR:,,,,,,,,,,,这个问题,本篇文章进行了详细的解答,同时本文还将给你拓展.net饼状图,,,ajax异步请求数据返回xml格式的数据、C++类

针对650 webpack DevServer和HMR:,,,,,,,,,,,这个问题,本篇文章进行了详细的解答,同时本文还将给你拓展.net 饼状图,,, ajax异步请求数据 返回xml格式的数据、C++ 类 调试出错,,求帮忙看看,,,、C++字符串取了串出现乱码,,,、、CSS控制前台样式在360和chrome的兼容问题,跪求高手帮忙,在线等,,,,,,,_html/css_WEB-ITnose等相关知识,希望可以帮助到你。

本文目录一览:

650 webpack DevServer和HMR:,,,,,,,,,,,

650 webpack DevServer和HMR:,,,,,,,,,,,

为什么要搭建本地服务器?


Webpack watch


webpack-dev-server

  • cnpm install --save-dev webpack-dev-server
  • 注意,脚本是 "serve": "webpack serve"


webpack-dev-middleware 【了解】


webpack-dev-middleware的使用


认识模块热替换(HMR)


开启HMR


框架的HMR


React的HMR

  • cnpm install -D @pmmmwh/react-refresh-webpack-plugin react-refresh


Vue的HMR

  • cnpm install vue-loader vue-template-compiler -D


HMR的原理


HMR的原理图


webpack.config.js

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');

module.exports = {
  // watch: true,
  mode: "development",
  entry: "./src/index.js",
  output: {
    filename: "bundle.js",
    path: path.resolve(__dirname, "./build")
  },
  // 专门为webpack-dev-server配置
  devServer: {
    hot: true
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/i,
        use: "babel-loader"
      },
      {
        test: /\.vue$/i,
        use: "vue-loader"
      },
      {
        test: /\.css/i,
        use: [
          "style-loader",
          "css-loader"
        ]
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: "./index.html"
    }),
    new ReactRefreshWebpackPlugin(),
    new VueLoaderPlugin()
  ]
}

package.json

{
  "name": "webpack_devserver",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack",
    "watch": "webpack --watch",
    "serve": "webpack serve"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.12.17",
    "@babel/preset-env": "^7.12.17",
    "@babel/preset-react": "^7.12.13",
    "@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
    "babel-loader": "^8.2.2",
    "css-loader": "^5.0.2",
    "html-webpack-plugin": "^5.2.0",
    "react-refresh": "^0.9.0",
    "style-loader": "^2.0.0",
    "vue-loader": "^15.9.6",
    "vue-template-compiler": "^2.6.12",
    "webpack": "^5.23.0",
    "webpack-cli": "^4.5.0",
    "webpack-dev-server": "^3.11.2"
  },
  "dependencies": {
    "express": "^4.17.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "vue": "^2.6.12",
    "webpack-dev-middleware": "^4.1.0"
  }
}

index.js

/**
 * 存在的问题:
 *  问题一: 每次修改源代码之后, 我们都需要重新执行npm run build
 *    * 通过watch监听源代码的变化
 * 
 * 目前的开发模式: 
 *    1.watch方案来监听文件的变化 
 *    2.通过live-server插件提供本地服务(当文件变化时,自动刷新页面)
 * 效率并不是特别高:
 *    1.对所有的源代码都重新进行编译
 *    2.编译成功后,都会生成新的文件(文件操作 file system)
 *    3.live-server属于VSCode插件(vim/webstorm) -> 不属于webpack给我们的解决方案
 *    4.live-server每次都会重新刷新整个页面
 * 
 *  webpack-dev-server: hot module replacement(HMR)
 */

import "./math";
import React from 'react';
import ReactDom from 'react-dom';
import ReactApp from './App.jsx';

import Vue from 'vue';
import VueApp from './App.vue';

console.log("Hello 哈哈哈");
console.log("abc");

// 【module是全局对象。】
if (module.hot) {
  module.hot.accept("./math.js", () => {
    console.log("math模块发生了更新~");
  });
}

// React的代码
ReactDom.render(<ReactApp/>, document.getElementById("app"));

// Vue的代码
new Vue({
  render: h => h(VueApp)
}).$mount("#root");

App.vue

<template>
  <div id="app">
    <h2>{{ message }}</h2>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        message: "Hello 哈哈哈",
      };
    },
  };
</script>

<style scoped>
  .title {
    color: blue;
  }
</style>

App.jsx

import React, { Component } from "react";

class App extends Component {
  constructor(props) {
    super(props);

    this.state = {
      message: "Hello React",
    };
  }

  render() {
    return (
      <div>
        <h2>{this.state.message}</h2>
      </div>
    );
  }
}

export default App;

babel.config.js

module.exports = {
  presets: [
    ["@babel/preset-env"],
    ["@babel/preset-react"],
  ],
  plugins: [
    ["react-refresh/babel"]
  ]
}

output的publicPath


devServer的publicPath


devServer的contentBase


hotOnly、host配置


port、open、compress



Proxy代理


changeOrigin的解析


historyApiFallback


resolve模块解析


确实文件还是文件夹


extensions和alias配置


目录结构


webpack.config.js

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');

module.exports = {
  // watch: true,
  mode: "development",
  entry: "./src/index.js",
  output: {
    filename: "bundle.js",
    // 打包后的文件的输出目录
    path: path.resolve(__dirname, "./build"),
    // publicPath:在打包之后的静态资源前面进行一个路径的拼接,默认值是一个空字符串 【拼接:主机名 + publicPath + bundle.js】
    // js/bundle 会拼接成 -> ./js/bundle.js,通过相对路径访问
    // publicPath: "./"
    // publicPath: "/abc"
  },
  // 专门为webpack-dev-server
  // devServer为开发过程中, 开启一个本地服务
  devServer: {
    hot: true,
    hotOnly: true,
    // host: "0.0.0.0", // 经测试,不能通过 http://0.0.0.0:端口/ 进行访问
    // port: 7777,
    // open: true,
    compress: true,
    // 通过src与进入的静态资源会去配置的contentBase中查找【本地服务的路径是在"./why"】
    contentBase: path.resolve(__dirname, "./why"),
    watchContentBase: true, // abc.js代码改变后,自动刷新浏览器
    // 开发环境中,devServer的publicPath 和 output的publicPath一致
    // publicPath: "/abc",
    proxy: {
      // "/why": "http://localhost:8888"
      "/why": {
        // 映射,"/why"相当于"http://localhost:8888"
        target: "http://localhost:8888", 
        pathRewrite: {
          "^/why": ""
        },
        secure: false, // 支持https
        changeOrigin: true // 如果服务器做了验证,就要设置为true
      }
    },
    // historyApiFallback: true
    historyApiFallback: {
      rewrites: [
        {from: /abc/, to: "/index.html"}
      ]
    }
  },
  resolve: {
    extensions: ['.wasm', '.mjs', '.js', '.json', '.jsx', '.ts', '.vue'],
    alias: {
      "@": path.resolve(__dirname, "./src"),
      "pages": path.resolve(__dirname, "./src/pages")
    }
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/i,
        use: "babel-loader"
      },
      {
        test: /\.vue$/i,
        use: "vue-loader"
      },
      {
        test: /\.css/i,
        use: [
          "style-loader",
          "css-loader"
        ]
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: "./index.html"
    }),
    new ReactRefreshWebpackPlugin(),
    new VueLoaderPlugin()
  ]
}

index.js

import axios from 'axios';

import React from 'react';
import ReactDom from 'react-dom';
import ReactApp from './App.jsx';

import Vue from 'vue';
import VueApp from './App.vue';

import "./math";

console.log("Hello Coderwhy");
console.log("abc");

if (module.hot) {
  module.hot.accept("./math.js", () => {
    console.log("math模块发生了更新~");
  });
}

// React的代码
ReactDom.render(<ReactApp/>, document.getElementById("app"));

// Vue的代码
new Vue({
  render: h => h(VueApp)
}).$mount("#root");

// axios网络请求
// changeOrigin的解析:--> 因为使用了代码,默认情况下它的值是 http://localhost:8080,服务器接收来源的时候,如果不去对它做额外的配置,服务器会认为这次请求的来源就是 http://localhost:8080。本来应该是target对应的 "http://localhost:8888",但是做了代理,请求变成了http://localhost:8080。如果服务器没有对来源做校验,此时不会有问题。如果服务器为了防止通过代理的方式爬服务器的数据,做了校验,校验这次请求是不是在http://localhost:8888,发现是8080,不是8888,就不会返回数据,所以要改回成8888。用了第三方库,取代理服务器,把源换成target的值http://localhost:8888,服务器就会验证通过。
axios.get("http://localhost:8080/why/moment").then(res => {
  console.log(res);
}).catch(err => {
  console.log(err);
});


.net 饼状图,,, ajax异步请求数据 返回xml格式的数据

.net 饼状图,,, ajax异步请求数据 返回xml格式的数据



首先引用js

<script src="../../js/FusionCharts.js" type="text/javascript"></script>

选择flash 饼状图



function NowResidentsParameter() { $.ajax({ type: "Post",url: "/Parameter/Count",data: “",contentType: "application/json; charset=utf-8",success: function (result) { //饼 var fusionChartPie = new FusionCharts('../../swf/Pie2D.swf','',450,450); fusionChartPie.setdataxML(result); fusionChartPie.render("div_RegistrationCount"); } }); }

C++ 类 调试出错,,求帮忙看看,,,

C++ 类 调试出错,,求帮忙看看,,,

C++程序调试时出错,,求帮忙看看。。

 

 

 

 

#include <iostream>

using namespace std;
class Clock
{
    public:
    void sethour(int h){
        hour=h;
    }
    void setminute(int m){
        minute=m;
    }
    void setsecond(int s){
        second=s;
    }
    void time(){
        cout<<"the time now is:"<<hour<<":"<<minute<<":"<<second<<endl;
    }
        private:
     int hour,minute,second;
};
int main(int argc, char *argv[])
{
    Clock *a,*b,c,d;
    d=c;
    c.sethour(1);
    c.setminute(2);
    c.setsecond(3);
    b=a;
    a->sethour(4);
    a->setminute(5);
    a->setsecond(6);
    c.time();
    d.time();
    a->time();
    b->time();
    return 0;

}

C++字符串取了串出现乱码,,,、

C++字符串取了串出现乱码,,,、

#include <iostream>
#include <string>
using namespace std;
char * substr(int pos,int n,char* s);

int main()
{
char * s1="abcdefghijklmn";
char *s2="opqrstuvwxyz"; //定义两个字符串


int pos,n; //抽取的开始位置和长度
cout<<"请输入取字串的位置和取子串的长度\n";

cin>>pos>>n;
char *s3;
s3=new char[n];
cout<<substr(pos,n,s1);
cout<<s3<<endl;
return 0;

}


char * substr(int pos,int n,char * s)
{
char* temp;
temp=new char[n+1];
int i;
for(i=pos;i<pos+n;i++)
{
temp[i]=s[i];
}
return temp;
}

CSS控制前台样式在360和chrome的兼容问题,跪求高手帮忙,在线等,,,,,,,_html/css_WEB-ITnose

CSS控制前台样式在360和chrome的兼容问题,跪求高手帮忙,在线等,,,,,,,_html/css_WEB-ITnose

下面代码,没加红色字体时,在360和chrome分别是第一张和第二张图的效果,
加了红色字体后,在360和chrome分别是第三张和第四张图的效果
我就是想做个搜索框的下拉框,产品列表紧靠着上面的输入框就好,可是在不同的浏览器效果还不同,郁闷





nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">










autocomplete="off">
id="keywordid" placeholder="输入应用名称搜索" onkeyup="keyupevent(event);" />



  • onmouseover="mo(this.value)">产品1
  • onmouseover="mo(this.value)">产品2
  • onmouseover="mo(this.value)">产品3
  • onmouseover="mo(this.value)">产品4










回复讨论(解决方案)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=7"><link rel="shortcut icon" href="./images/favicon.ico"><style type="text/css">body {background: #f1f2f6;overflow: hidden;font-family: microsoft yahei;}.ulclass {border: 1px solid #000;list-style: none;width: 308px;padding: 0px;margin:0;}.selectclass {background: #36C;font-size: 12px;color: #FFF;}.selectclass span {color: #FFF;}.liclass {line-height: 16px;font-size: 12px;padding: 2px;}.spanclass {float: right;font-size: 12px;color: #008000;margin-top: -18px;}.header {width: 980px;height: 95px;margin: 0px auto 10px;overflow: visible;zoom: 1;}.header .searchBox {width: 350px;margin-top: 40px;float: right;background-color: #f1f2f6;border: none;border-radius: 5px;overflow: visible;position:relative;}.header .searchBox .input_text {border: 1px solid #dfdfdf;border-right: none;height: 18px;line-height: 18px;margin: 0px;width: 300px;font-size: 14px;font-weight: bold;background: #fff;float: left;border-top-left-radius: 4px;border-bottom-left-radius: 4px;padding: 10px 0 10px 10px;letter-spacing: normal;word-spacing: normal;text-transform: none;text-shadow: none;display: inline-block;text-align: start;font-family: Tahoma, Helvetica, ''SimSun'', sans-serif;}.header .searchBox .input_button {border: 1px solid #00a0e5;border-left: none;height: 40px;width: 38px;padding: 0px;margin: 0px;background: #00a0e5 url(../images/search_bg.png);float: left;border: none;border-top-right-radius: 4px;border-bottom-right-radius: 4px;box-shadow: none;}.header .suggest {position:absolute;top:38px;left:0;z-index: 9999;}.navfixed {width: 100%;height: 50px;line-height: 50px;margin-top: 10px;background: #00a0e5;overflow: hidden;}</style></head><body><div><div><form action="./search/index.jsp" method="post" name="search"autocomplete="off"><inputtype="text" name="keyword"id="keywordid" placeholder="输入应用名称搜索" onkeyup="keyupevent(event);" /><inputtype="submit" value=""></form><div><ul><livalue="1" onclick="form_submit()"onmouseover="mo(this.value)">产品1</li><livalue="2" onclick="form_submit()"onmouseover="mo(this.value)">产品2</li><livalue="3" onclick="form_submit()"onmouseover="mo(this.value)">产品3</li><livalue="4" onclick="form_submit()"onmouseover="mo(this.value)">产品4</li></ul></div></div></div><div id="mainnav"></div></body></html>
登录后复制


定位没有掌握好,好好看看定位这一块多练习就懂了……

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=7"><link rel="shortcut icon" href="./images/favicon.ico"><style type="text/css">body {background: #f1f2f6;overflow: hidden;font-family: microsoft yahei;}.ulclass {margin-left: 0px;margin-top: 0px;border: 1px solid #000;list-style: none;width: 308px;padding: 0px;position: absolute;background: #FFF;}.selectclass {background: #36C;font-size: 12px;color: #FFF;}.selectclass span {color: #FFF;}.liclass {line-height: 16px;font-size: 12px;padding: 2px;}.spanclass {float: right;font-size: 12px;color: #008000;margin-top: -18px;}.header {width: 980px;height: 95px;margin: 0px auto 10px;overflow: visible;zoom: 1;}.header .searchBox {width: 350px;margin-top: 40px;float: right;background-color: #f1f2f6;border: none;border-radius: 5px;overflow: visible;}.header .searchBox .input_text {border: 1px solid #dfdfdf;border-right: none;height: 18px;line-height: 18px;margin: 0px;width: 300px;font-size: 14px;font-weight: bold;background: #fff;float: left;border-top-left-radius: 4px;border-bottom-left-radius: 4px;padding: 10px 0 10px 10px;letter-spacing: normal;word-spacing: normal;text-transform: none;text-shadow: none;display: inline-block;text-align: start;font-family: Tahoma, Helvetica, ''SimSun'', sans-serif;}.header .searchBox .input_button {border: 1px solid #00a0e5;border-left: none;height: 40px;width: 38px;padding: 0px;margin: 0px;background: #00a0e5 url(../images/search_bg.png);float: left;border: none;border-top-right-radius: 4px;border-bottom-right-radius: 4px;box-shadow: none;}.header .suggest {position: relative;z-index: 9999; float:left;padding-right: 100%;}.navfixed {width: 100%;height: 50px;line-height: 50px;margin-top: 10px;background: #00a0e5;overflow: hidden;}</style></head><body><div><div><form action="./search/index.jsp" method="post" name="search"autocomplete="off"><inputtype="text" name="keyword"id="keywordid" placeholder="输入应用名称搜索" onkeyup="keyupevent(event);" /><inputtype="submit" value=""><div><ul><livalue="1" onclick="form_submit()"onmouseover="mo(this.value)">产品1</li><livalue="2" onclick="form_submit()"onmouseover="mo(this.value)">产品2</li><livalue="3" onclick="form_submit()"onmouseover="mo(this.value)">产品3</li><livalue="4" onclick="form_submit()"onmouseover="mo(this.value)">产品4</li></ul></div></form></div></div><div id="mainnav"></div></body></html>
登录后复制

我们今天的关于650 webpack DevServer和HMR:,,,,,,,,,,,的分享已经告一段落,感谢您的关注,如果您想了解更多关于.net 饼状图,,, ajax异步请求数据 返回xml格式的数据、C++ 类 调试出错,,求帮忙看看,,,、C++字符串取了串出现乱码,,,、、CSS控制前台样式在360和chrome的兼容问题,跪求高手帮忙,在线等,,,,,,,_html/css_WEB-ITnose的相关信息,请在本站查询。

本文标签: