Laravel MIX:将项目放在子文件夹中时重写路径
大家好,我最近需要以不同的方式为本地服务器和生产配置 Laravel mix,问题是在我的生产中,项目位于一个子文件夹中,该项目是一个包含 Laravel、Vue 和 Inertiajs 的整体,经过几次 挣扎,我能够解决问题,我做了以下更改:
在 .env 添加
APP_URL=https://domain.com/subfolder
MIX_ASSET_URL=https://domain.com/subfolder
并在 config/app.php 中添加了以下代码
...
'mix_url' => env('MIX_ASSET_URL', null),
最后,
我更新了我的 webpack.mix.js
并在 webpack.mix.js 文件中的 webpackConfig 输出中添加了公共 url
const mix = require('laravel-mix');
const path = require('path');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel applications. By default, we are compiling the CSS
| file for the application as well as bundling up all the JS files.
|
*/
mix.js('resources/js/app.js', 'public/js')
.postCss('resources/css/app.css', 'public/css', [
//
])
.alias({
ziggy: path.resolve('vendor/tightenco/ziggy/dist/vue'),
})
.vue({ version: 3 });
if (mix.inProduction()) {
mix.webpackConfig({
output: {
chunkFilename: 'js/[name].js?id=[chunkhash]',
publicPath: '/subfolder/'
},
resolve: {
alias: {
'@': path.resolve('resources/js')
}
}
});
} else {
mix.webpackConfig({
output: {
chunkFilename: 'js/[name].js?id=[chunkhash]',
}
});
}
我希望你喜欢阅读!
转 :
https://dev.to/saymon/laravel-mix-rewrite-path-when-place-project-in-subfolder-2325
相关文章