我实际上是在复制Laravel Vapor文档中声明的内容,但无济于事。为了简短起见,我无法访问泰勒说在构建步骤中注入的ASSET_URL
环境变量。
现在请注意,将相同的环境变量注入到应用程序中,这就是为什么index.blade.php上的Blade中的assets()
和mix()
帮助器可以正常工作的原因。但是,我的问题是访问ASSET_URL
内部的webpack.mix.js
。
这来自我下面的Github动作。您可以看到ASSET_URL
在登录时为空。
> @ production /github/workspace/.vapor/build/app
> cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js
ASSET URL IS:
DONE Compiled successfully in 26754ms11:23:07 PM
webpack.mix.js。
// To deal with Laravel Vapor
if (mix.inProduction()) {
const ASSET_URL = process.env.ASSET_URL;
console.log("ASSET URL IS: " + ASSET_URL);
mix.webpackConfig(webpack => {
return {
plugins: [
new webpack.DefinePlugin({
"process.env.ASSET_PATH": JSON.stringify(ASSET_URL)
})
],output: {
publicPath: ASSET_URL
}
};
});
在Laracasts论坛上的建议解决方案
- Paul Marshall建议他通过使用
window.__ASSET_URL__ = '{{ env('ASSET_URL') }}';
找到一种解决方法,但我不喜欢这种方法,除非万不得已。 - @fylzero建议我在环境文件中进行
MIX_ASSET_URL="${ASSET_URL}"
来查看Mix是否可以读取。不是。