gpt4 book ai didi

laravel - 在代客安全站点 SSL 错误中使用 laravel-mix 热重新加载 Webpack

转载 作者:行者123 更新时间:2023-12-04 00:24:16 25 4
gpt4 key购买 nike

正在运行 Laravel Valet在本地托管站点,以及 Laravel Mix使用 Webpack 开发服务器编译 Assets 并执行 HMR

我通过

在本地保护了 .dev 站点
valet secure

在运行 npm run watch

时调用 {{ mix('js/app.js') }} 没问题

但是每当我想通过运行 hot npm 脚本来利用热重载时,我都会得到这个

GET https://localhost:8080//css/app.css net::ERR_CERT_AUTHORITY_INVALID

GitHub issue 建议添加 --https flag,我试过了,还有 --http

我什至通过 --disable-host-check 标志禁用主机检查并清除所有可能的缓存,甚至尝试了新的 git clone 但无济于事

这是我的 package.json

{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --https --disable-host-check --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"@kazupon/vue-i18n-loader": "^0.3.0",
"cross-env": "^5.1",
"eslint-plugin-vue": "^5.2.3",
"laravel-mix": "^4.0.7",
"resolve-url-loader": "^2.3.1",
"sass": "^1.21.0",
"sass-loader": "^7.1.0",
"vue-template-compiler": "^2.6.10"
},
"dependencies": {
"algoliasearch": "^3.33.0",
"axios": "^0.19.0",
"font-awesome": "^4.7.0",
"jquery": "^2.1.1",
"lato-webfont": "^2.15.1",
"modernizr": "^3.7.1",
"raleway-webfont": "^3.0.1",
"raphael": "^2.1.4",
"vlightbox": "^2.0.2",
"vue": "^2.5.17",
"vue-i18n": "^8.12.0",
"vue-instantsearch": "^2.2.1"
}
}

webpack.mix.js 如果有用的话

const mix = require('laravel-mix');

// Extend Mix with the "i18n" method, that loads the vue-i18n-loader
mix.extend('i18n', new class {
webpackRules() {
return [{
resourceQuery: /blockType=i18n/,
type: 'javascript/auto',
loader: '@kazupon/vue-i18n-loader',
}, ];
}
}(), );

// Call the .i18n() (to load the loader) before .js(..., ...)
mix.i18n()
.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css');

我做错了什么?这可以复制吗?我也应该找到保护 localhost:8080 的方法吗?

最佳答案

因此,要使其正常工作,请指示 laravel mix 在选项对象中为 HMR 使用特定域和端口

webpack.mix.js

// Get the APP_URL from .env and remove protocol
let url = process.env.APP_URL.replace(/(^\w+:|^)\/\//, '');
mix.options({
hmrOptions: {
host: url,
port: 8080 // Can't use 443 here because address already in use
}
});

保留 --https 标志以指示 webpack-dev-server 使用什么协议(protocol),但是,删除 --disable-host-check 因为它是多余的(谷歌浏览器对 .dev 域有严格的 HSTS 政策)

现在鉴于 valet secure 为每个域生成 SSL key 和证书,指示 webpack-dev-serverhot 中也使用它们package.json

的code>脚本
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js
--inline --hot --https
--key /home/caddy/.valet/Certificates/laravel.dev.key
--cert /home/caddy/.valet/Certificates/laravel.dev.crt --config=node_modules/laravel-mix/setup/webpack.config.js",

replace /home/caddy/ by your own absolute path

运行

npm run hot

现在热重载在安全的代客站点上运行良好

Source

关于laravel - 在代客安全站点 SSL 错误中使用 laravel-mix 热重新加载 Webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58088838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com