Laravel + Angularが使えるように環境設定しましたが動きません。
自分が考えられることはかなり手を尽くしましたが、どうしても動かないです。どうかお助けください...
できている部分(基本的な設定)
・public/js/app.jsにwebpack.mix.jsの内容をnpm run devで集約
できていない部分
・Angularプロジェクトの初期画面が出ない
現在まで試してみたこと
・ブラウザのスーパーリロード
・public/js/app.jsの src参照パスを、{{mix('/js/app.js')}}などに変更
こちらのサイトをメインに参考にしています。
https://mrkmyki.com/laravel%E5%86%85%E3%81%A7angular%E3%82%92%E4%BD%BF%E3%81%88%E3%82%8B%E3%82%88%E3%81%86%E3%81%AB%E3%81%99%E3%82%8B%E3%80%82
環境
・php 7.2
app-rootが効いてないように見えるのでその部分についてのミスかもしれませんが、Laravel + Angularに関しては各々3日程度しか触っていないので詳しい部分まで理解ができておりません。
お助けいただけると幸いです。
resources/views/welcome.blade.php
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Nunito', sans-serif;
font-weight: 200;
height: 100vh;
margin: 0;
}
.full-height {
height: 100vh;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}
.position-ref {
position: relative;
}
.top-right {
position: absolute;
right: 10px;
top: 18px;
}
.content {
text-align: center;
}
.title {
font-size: 84px;
}
.links > a {
color: #636b6f;
padding: 0 25px;
font-size: 13px;
font-weight: 600;
letter-spacing: .1rem;
text-decoration: none;
text-transform: uppercase;
}
.m-b-md {
margin-bottom: 30px;
}
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
@if (Route::has('login'))
<div class="top-right links">
@auth
<a href="{{ url('/home') }}">Home</a>
@else
<a href="{{ route('login') }}">Login</a>
@if (Route::has('register'))
<a href="{{ route('register') }}">Register</a>
@endif
@endauth
</div>
@endif
<div class="content">
<div class="title m-b-md">
Laravel
</div>
<app-root>Loading..</app-root>
<div class="links">
<a href="https://laravel.com/docs">Docs</a>
<a href="https://laracasts.com">Laracasts</a>
<a href="https://laravel-news.com">News</a>
<a href="https://blog.laravel.com">Blog</a>
<a href="https://nova.laravel.com">Nova</a>
<a href="https://forge.laravel.com">Forge</a>
<a href="https://vapor.laravel.com">Vapor</a>
<a href="https://github.com/laravel/laravel">GitHub</a>
</div>
</div>
</div>
<script src="js/app.js"></script>
</body>
public/js/app.js
...(function () {
_angular_core__WEBPACK_IMPORTED_MODULE_0__["ɵsetClassMetadata"](AppComponent, [{
type: _angular_core__WEBPACK_IMPORTED_MODULE_0__["Component"],
args: [{
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
}]
}], null, null);...
このtemplateUrlの部分が気になっています(おそらく問題はないとおもいますが..)
webpack.mix.js
const 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.js('resources/js/app.js', 'public/js')
// .sass('resources/sass/app.scss', 'public/css');
mix.webpackConfig({
resolve: {
extensions: ['.ts']
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader'
}
]
}
});
mix.js(['public/dist/runtime.js',
'public/dist/styles.js',
'public/dist/polyfills.js',
'public/dist/vendor.js',
'public/dist/main.js'
], 'public/js/app.js');
if (mix.inProduction()) {
mix.version();
}