我实际上是在复制 Laravel Vapor 文档所述的内容,但无济于事。因此,为了简短起见,我无法访问ASSET_URL
Taylor 所说的在构建步骤中注入的环境变量。
现在请注意,相同的环境变量被注入到应用程序中,这就是为什么index.blade.php 上的刀片中的assets()
和帮助程序工作得很好。mix()
但是,我的问题是访问ASSET_URL
inside 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 是否可以读取。它没有。