所以我使用代理进行 API 调用,如下所示:
vue.config.js:
module.exports = {
devServer: {
proxy: 'http://www.pathofexile.com/'
}
}
Run Code Online (Sandbox Code Playgroud)
xxx.vue:
axios.get("http://localhost:8080/api/public-stash-tabs").then..
Run Code Online (Sandbox Code Playgroud)
这有效!现在,当我也想从不同的站点进行 API 调用时,我不知道该怎么做。我想要的是这样的东西:
vue.config.js:
module.exports = {
devServer: {
proxy: {
'http://localhost:8080/one/': {
target: 'http://www.pathofexile.com/',
changeOrigin: true
},
'http://localhost:8080/two/': {
target: 'https://api.poe.watch/',
changeOrigin: true
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
xxx.vue:
axios.get("http://localhost:8080/one/api/public-stash-tabs").then..
axios.get("http://localhost:8080/two/id").then..
Run Code Online (Sandbox Code Playgroud)
但似乎什么也没发生,我收到 404 错误,因为它尝试从 http://localhost:8080/api/public-stash-tabs获取某些内容
我是否走在正确的轨道上,我是否错过了一些东西?或者这不是要走的路?
因此,对于我的项目(使用 React 和 Redux),我一直遇到“找不到模块”的错误。我已经在 google 和 stackoverflow 上搜索了几个解决方案,并且看到人们说我的 node_modules 出了问题,所以我删除了它们,并且还 npm install (重新安装)。错误仍然存在,我认为这与我的 webpack.config.js 文件有关......
\n我只是希望构建能够正常工作并且反应元素和组件能够渲染。
\n错误
\nModule not found: Error: Can't resolve './node_modules/react' in '/Users/<user-name>/Documents/gift-test/client'\n\nERROR in ./client/index.js\nModule not found: Error: Can't resolve './node_modules/react' in '/Users/<user-name>/Documents/gift-test/client'\n @ ./client/index.js 1:0-41 15:21-26 17:16-21\n\nERROR in ./client/index.js\nModule not found: Error: Can't resolve './node_modules/react-dom' in '/Users/<user-name>/Documents/gift-test/client'\n @ ./client/index.js 2:0-50 15:0-6\n\nERROR in ./client/index.js\nModule not found: Error: Can't resolve './node_modules/react-redux' in '/Users/<user-name>/Documents/gift-test/client'\n @ ./client/index.js 3:0-54 15:41-49\n\nERROR in ./client/store.js\nModule not found: Error: Can't resolve './node_modules/redux' …Run Code Online (Sandbox Code Playgroud) 我正在尝试将mediainfo.js与 React.js 一起使用。
查看上述站点的React.js中的使用示例,它是由“webpack.config.js”设置的。但是,当我使用 构建环境时create-react-app,“webpack.config.js”被包装,并且似乎在不执行“eject”命令的情况下无法对其进行编辑。
如果使用npm包“react-app-rewired”,则可以在不执行reject命令的情况下对其进行编辑,所以我尝试了。
// config-override.js (overwrites webpack.config.js)
const { resolve } = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const wasmFile = resolve(
__dirname,
'node_modules',
'mediainfo.js',
'dist'
);
const dist = resolve('build', 'static', 'js');
// template from https://www.npmjs.com/package/react-app-rewired
module.exports = {
webpack: function(config, env) {
config.plugins.push(new CopyPlugin({
patterns: [
{ from: wasmFile, to: dist },
],
}),)
return config;
},
}
Run Code Online (Sandbox Code Playgroud)
这是整个项目。
https://github.com/ottonove/test_mediainfo
通过“npm run build”生成的运行正常,但是当我通过“npm run start”运行它时,出现以下错误。
Uncaught (in promise) RuntimeError: abort(CompileError: WebAssembly.instantiate(): expected …Run Code Online (Sandbox Code Playgroud) 我想与使用Windows 身份验证ng serve(NTLM)保护的后端服务器一起使用。这与这些帖子(示例 1、示例 2 )中的情况几乎相同,只不过服务器是通过HTTPS访问的。
当我尝试使用相同的建议解决方案(适用于 HTTP)时,我收到404错误(但当然可以通过此 URL 访问服务器,我可以直接使用浏览器进行测试)。
const Agent = require("agentkeepalive");
module.exports = {
'/api': {
target: "https://my-server.example.com",
secure: false,
changeOrigin: true,
agent: new Agent({
maxSockets: 100,
keepAlive: true,
maxFreeSockets: 10,
keepAliveMsecs: 100000,
timeout: 6000000,
keepAliveTimeout: 90000
}),
onProxyRes: proxyRes => {
const key = "www-authenticate";
proxyRes.headers[key] = proxyRes.headers[key] &&
proxyRes.headers[key].split(",");
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,包括一些诊断问题的方法,将不胜感激。
更新:使用 logLevel = "debug" 我得到以下堆栈跟踪(我不明白,因为相同的代理配置在 HTTPS 上运行良好,如果不是 Windows 配置的话):
TypeError [ERR_INVALID_PROTOCOL]: Protocol …Run Code Online (Sandbox Code Playgroud) 我对 webpack 很陌生,所以请宽容,但我不明白为什么它在检测到修改时不重新加载页面。对于某些旧版本的 webpack,只需运行 webpack-dev-server 就足够了,但对于这些最新版本,我无法到达那里。
这是我的配置:
const path = require('path')
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'public/scripts'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env']
]
}
}
}
]
},
target: ['web', 'es5'],
devServer: {
contentBase: path.resolve(__dirname, 'public'),
watchContentBase: true
},
devtool: 'source-map'
}
Run Code Online (Sandbox Code Playgroud)
这是我的脚本:
"scripts": {"dev": "webpack serve --mode=development"}
Run Code Online (Sandbox Code Playgroud)
我正在运行的版本:
"webpack": "^5.11.0",
"webpack-cli": "^4.3.0",
"webpack-dev-server": "^3.11.0"
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助
我正在尝试在带有Themekit 的自定义 Webpack 项目中以及运行时使用 TailwindCSS JIT 功能yarn startwebpack 开发服务器时 HMR 不断重新编译。
代码: https: //github.com/3daddict/themekit-webpack/pull/63
\n包.json
\n{\n"scripts": {\n...\n "start": "TAILWIND_MODE=watch webpack serve --mode=development --config webpack.dev.js",\n...\n }\n}\nRun Code Online (Sandbox Code Playgroud)\ntailwind.config.js
\nmodule.exports = {\n mode: \'jit\',\n purge: {\n enabled: true,\n content: [\n \'./dist/**/*.liquid\',\n \'./dist/**/*.js\',\n ],\n },\n ...\n}\n\nRun Code Online (Sandbox Code Playgroud)\nsrc/组件/tailwind.css
\n/* purgecss start ignore */\n@tailwind base;\n@tailwind components;\n/* purgecss end ignore */\n@tailwind utilities;\n...\nRun Code Online (Sandbox Code Playgroud)\nWebpack 开发服务器热模块重新加载不断地重新编译。我一直在试图找出原因。
\n\xe2\x84\xb9 \xef\xbd\xa2wdm\xef\xbd\xa3: webpack compiled successfully\n\xe2\x84\xb9 \xef\xbd\xa2wdm\xef\xbd\xa3: Compiled successfully.\n\xe2\x84\xb9 \xef\xbd\xa2wdm\xef\xbd\xa3: Compiling...\n\xe2\x84\xb9 \xef\xbd\xa2wdm\xef\xbd\xa3: …Run Code Online (Sandbox Code Playgroud) 我在尝试在 Single-SPA 应用程序中启动子应用程序时遇到错误。基本上,我正在尝试开发一种 util 应用程序(Single-SPA 中的子应用程序),其中包含 Sockjs、Stomp-client 等。我删除了节点模块和 package-lock.json 并再次安装了节点模块。当我尝试启动应用程序时,我遇到以下错误。
Error:
[webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options has an unknown property 'firewall'. These properties are valid:
object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, liveReload?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, setupExitSignals?, static?, watchFiles?, webSocketServer? }
- options.client has an unknown property 'host'. These properties are valid:
object …Run Code Online (Sandbox Code Playgroud) 我在 webpack 5/Vuejs 3 应用程序中使用 webpack-dev-server 来利用在应用程序开发期间将代码更改保存在编辑器中后立即显示在浏览器中的功能(对该功能的详细解释我感兴趣,但我认为它在“热门”或“HMR”下交易)。
好处是这原则上是有效的。我可以在编辑器中更新 .vue 文件,保存它,查看 webpack-dev-server 重新编译,查看 JS 控制台日志,表明它检测到更改,并且更改(例如文本更改)显示在浏览器页面中。
但是,当在初始(硬)页面加载后导航到另一路由(URL)时,导致初始页面 URL 与当前 URL 不同,代码更改不会反映在浏览器页面中。所有其他步骤(例如编译、客户端上的更改检测、重新加载更改、日志)都会执行,但只是不更新浏览器页面。然而,当用户导航到其他地方并返回时,它会更新页面。
这个问题听起来很熟悉吗?我认为即使在单页应用程序中导航到另一个路由(URL)时,实时更新也应该正常工作(如果我的期望是错误的,请更正)。
我的相关部分webpack.conf.js(恕我直言,没什么特别的):
devServer: {
historyApiFallback: {
rewrites: [{
from: /.*/,
to: path.posix.join(config.dev.assetsPublicPath, 'index.html')
}]
},
hot: true,
host: HOST || config.dev.host,
port: PORT || config.dev.port,
open: config.dev.autoOpenBrowser,
proxy: config.dev.proxyTable
}
Run Code Online (Sandbox Code Playgroud)
更新
有趣的是,<style>即使初始页面加载 URL 已更改,该部分的更新也会立即反映出来。
在成功构建的 webpack 包上运行“npx webpack 服务器”,发生错误时的输出并不能告诉我太多信息(错误:“错误标签”位于 webpack 开发服务器代码深处),您在哪里可以看到更多信息/详细信息?这是输出:
npx webpack 服务
(node:31820) [DEP_WEBPACK_DEV_SERVER_HTTPS] DeprecationWarning: 'https' option is deprecated. Please use the 'server' option.
(Use `node --trace-deprecation ...` to show where the warning was created)
<i> [webpack-dev-server] SSL certificate: C:\Code\pl-security-audit-hub\PrecisionLender.SecurityAuditHub.API\ClientApp\node_modules\.cache\webpack-dev-server\server.pem
<w> [webpack-dev-server] "hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.
<i> [webpack-dev-server] [HPM] Proxy created: ** -> https://localhost:5510
[webpack-cli] Error: wrong tag
at Object.createSecureContext (_tls_common.js:271:19)
at Server.setSecureContext (_tls_wrap.js:1331:27)
at Server (_tls_wrap.js:1186:8)
at new …Run Code Online (Sandbox Code Playgroud) I\xe2\x80\x99m 使用react-app-rewired并且我想禁用每次编译时出现的 Typescript 警告覆盖。由于我不明白的原因,叠加层上出现了 VSCode Typescript 检查器未检测到的警告;webpack 是一个更严格的执行者(实际上比我想要的更严格)。
不管怎样,我尝试过react-app-rewired start --no-client-overlay,我为我的config-overrides.js文件尝试过这个:
module.exports = {\n webpack: function (config, _) {\n config.devServer = {\n client: {\n overlay: false\n }\n }\n return config\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n两者都没有任何效果。知道如何禁用覆盖会很好,但同样好的解决方案是如何让编译器使用与 VSCode 相同的严格级别。
\nwebpack ×8
javascript ×3
reactjs ×3
vue.js ×2
angular-cli ×1
jit ×1
npm ×1
proxy ×1
react-redux ×1
shopify ×1
single-spa ×1
tailwind-css ×1
typescript ×1
vue-cli ×1
webassembly ×1