この本を読み進めていると急に本通りに進めなくなってしまった
3章の序盤にwebpack.mix.jsについての説明があるけどそもそもファイルが存在しない、、、
環境構築の際しっかり本とバージョンがあっていなかったのかLaravel mixではなくてLaravel viteというものになってしまっている。いろいろしらべながらぐちゃぐちゃにいじったけどおそらく以下の内容で治るかな、、とは思う。
おもったよりがっつり作業なのでバックアップをしておくことをおすすめする、、、
- Laravel Mixのインストール
sail npm install --save-dev laravel-mix
- app.jsの修正
require ('./bootstrap');
const appName = window.document.getElementsByTagName('title')[0]?.innerText || 'Laravel';
InertiaProgress.init({ color: '#4B5563' });
- package.jsonの修正
{
"private": true,
"type": "commonjs",
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"alpinejs": "^3.4.2",
"autoprefixer": "^10.4.2",
"axios": "^1.6.4",
"babel-loader": "^9.2.1",
"laravel-mix": "^6.0.49",
"postcss": "^8.4.31",
"resolve-url-loader": "^5.0.0",
"sass": "^1.81.0",
"sass-loader": "^12.6.0",
"tailwindcss": "^3.1.0"
}
}
- webpack.mix.jsの作成 package.jsonなどの環境設定ファイルと同じ階層に作成し内容を以下にする
const mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| 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', [
//
]);
- postcss.config.jsの修正(必要かわからない、、) いろいろ調べていた中で変更していたから蛇足かもしれない、、
module.exports= {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
- 依存関係のインストール
rm -rf node_modules package-lock.json
npm install
- 再度実行
sail npm run development
やってみた中でのポイント
- import 文は使用できずrequireを使用した書き方にする
- インターネットで調べたnpm~コードを実行する際Sail npm~
他にもbabelとか追加しちゃったけどあんまり必要ないとは、、思う
