Я изо всех сил пытался в течение двух дней, но все еще не смог отобразить компоненты React с использованием Laravel Mix, когда я установил псевдоним своего домена в конфигурации Apache2.
domain name : http://dev.propertydodo.ae
Alias /admin-panel /var/www/html/pdd-admin/public
complete path is http://dev.propertydodo.ae/admin-panel
To fetch api its working path is http://dev.propertydodo.ae/admin-panel/api/v1
Ниже приведена моя конфигурация Laravel Mix.
let mix = require('laravel-mix');
/*
|-------------------------------------------------------------------- ------
| Mix Asset Management
|-------------------------------------------------------------------- ------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.webpackConfig({
module: {
rules: [
{
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
loaders: [
'babel-loader?presets[]=react,presets[]=es2015,presets[]=stage-0',
]
}
],
}
}).react('resources/assets/js/locations.js', 'public/js')
.react('resources/assets/js/dashboard.js', 'public/js')
.react('resources/assets/js/payment.js', 'public/js')
.sourceMaps()
.sass('resources/assets/sass/app.scss', 'public/css');
Ниже приведен файл index.blade.php, в котором я отображаю location.js, скомпилированный Babel Файлы ресурсов React в один файл JS.
<div id='locations' class="content-wrapper">
</div>
<script src="{{route('baseurl') . mix('js/locations.js') }}">
</script>