程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Webpack:无法获取 /大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Webpack:无法获取 /?

开发过程中遇到Webpack:无法获取 /的问题如何解决?下面主要结合日常开发的经验,给出你关于Webpack:无法获取 /的解决方法建议,希望对你解决Webpack:无法获取 /有所启发或帮助;

我有一个在周五工作的 React 微前端,特别是它的 container/ 部分。

现在我得到 CAnnot GET /

我运行了一个 netstat -aon,但没有在端口 8080 上侦听任何内容。

即使我尝试更改到 Webpack 中的另一个端口,我也会得到相同的结果。我的容器的 webpack 配置:

const {mergE} = require('webpack-merge');
const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
const commonConfig = require('./webpack.common');
const packageJson = require('../package.Json');

const devConfig = {
  mode: 'development',devServer: {
     port: 8080,historyAPIfallBACk: true,},plugins: [
    new ModuleFederationPlugin({
       name: 'container',remotes: {
          markeTing: 'markeTing@@R_502_6822@://localhost:8081/remoteEntry.Js'
       },shared: packageJson.dependencIEs,}),],};

module.exports = merge(commonConfig,devConfig);

我使用的 webpack 版本是 5.11.0。这是在 windows 10 机器上发生的。我在 MACBookPro 上有一个类似的项目,但我没有得到这种行为。

解决方法

我的 HtmlWebpackPlugin 文件中缺少 webpack.dev.js

const {mergE} = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
const commonConfig = require('./webpack.common');
const packageJson = require('../package.json');

const devConfig = {
  mode: 'development',devServer: {
     port: 8080,historyApifallBACk: true,},plugins: [
    new ModuleFederationPlugin({
       name: 'container',remotes: {
          markeTing: 'markeTing@http://localhost:8081/remoteEntry.js'
       },shared: packageJson.dependencies,}),new HtmlWebpackPlugin({
      tempate: './public/index.html'
    }),],};

module.exports = merge(commonConfig,devConfig);

大佬总结

以上是大佬教程为你收集整理的Webpack:无法获取 /全部内容,希望文章能够帮你解决Webpack:无法获取 /所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:/