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

主项目使用vue3.0 , 子项目使用ts+react , 刷新报错 #1299

Closed
yulintianxia opened this issue Mar 4, 2021 · 2 comments
Closed
Labels
duplicate This issue or pull request already exists

Comments

@yulintianxia
Copy link

主项目使用vue3.0,子项目使用ts+react,使用create-react-app脚手架,而后使用react-app-rewired命令时,看了issure,将
image
取消了热更新,项目刷新就报错,
image 这样修改报错,config.entry.filter 不是一个function,
image打印发现不是一个数组,但是去掉这句话,react项目刷新报错

@gongshun
Copy link
Collaborator

gongshun commented Mar 4, 2021

#340 (comment)

新增环境变量,写死端口就可以了

WDS_SOCKET_PORT=7100

@gongshun gongshun added the duplicate This issue or pull request already exists label Mar 4, 2021
@yulintianxia
Copy link
Author

把端口写进去也不行,感觉应该是版本的问题,我的vue 3.0+ts是最新的版本,react 项目使用的creat-react-app + ts官方脚手架,最新版本17,安装最新的react-app-rewired 可能最新版本改动,按照const { name } = require("./package.json");
const ReactRefreshPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const webpack = require("webpack");

module.exports = {
webpack: function override(config, env) {
config.output.library = ${name}-[name];
config.output.libraryTarget = "umd";
config.output.jsonpFunction = webpackJsonp_${name};

// Remove 'react-refresh' from the loaders.
for (const rule of config.module.rules) {
if (!rule.oneOf) continue;

for (const one of rule.oneOf) {
if (one.loader && one.loader.includes("babel-loader") && one.options && one.options.plugins) {
one.options.plugins = one.options.plugins.filter(
(plugin) => typeof plugin !== "string" || !plugin.includes("react-refresh")
);
}
}
}

config.plugins = config.plugins.filter(
(plugin) => !(plugin instanceof webpack.HotModuleReplacementPlugin) && !(plugin instanceof ReactRefreshPlugin)
);

return config;
},
devServer: (configFunction) => {
return function (proxy, allowedHost) {
const config = configFunction(proxy, allowedHost);
config.open = false;
config.hot = false;
config.headers = {
"Access-Control-Allow-Origin": "*",
};
return config;
};
},
}; 这个写法就Ok了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants