在使用 Laravel 裡面的 Vue Components 時,會需要使用到編譯 vue js 的功能

例如,修改 ExampleComponent.vue 之後,要執行以下語法才會將修改編譯到 app.js

npm run dev

Laravel 在 mac 或 linux 環境下,可能會出現 cross-env 相關錯誤訊息

解決的方式如下:

Step 1

將 package.json 裡面的 cross-env 全部改成 node_modules/cross-env/dist/bin/cross-env.js

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "node_modules/cross-env/dist/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.18",
        "bootstrap": "^4.0.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^2.0",
        "lodash": "^4.17.5",
        "popper.js": "^1.12",
        "vue": "^2.5.7"
    }
}

step 2

安裝或更新套件

npm install

step 3

再次執行

npm run dev