Laravel Mix / Webpack不会在通过babel()编译的脚本上触发监视功能

时间:2019-02-05 08:58:09

标签: javascript laravel webpack babel laravel-mix

我们通过babel()功能运行我们的一些javascript文件,Laravel mix提供了这些功能以向后兼容。

我们遇到的问题是,如果我们更改了app.js或app.scss中的任何内容,则会触发监视脚本,而Laravel mix会自动编译正确的脚本,但不会触发任何文件中的任何更改我们输入babel()。我们运行watch还是watch-poll都没关系。如果我们手动重新运行watch或运行production / dev,它会编译babel()脚本。

我试图在babel()watch上找到说明这种奇怪行为的文档。但找不到任何能解释这个奇怪问题的东西。

webpack.mix.js

mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
// Compile some resources independently to not include it in all pages.
.babel('resources/assets/js/cart.js', 'public/js/cart.js')
.babel('resources/assets/js/manage-addresses.js', 'public/js/manage-addresses.js')
.babel('resources/assets/js/catalog-overview-order.js', 'public/js/catalog-overview-order.js');

package.json

"scripts": {
        "dev": "npm run development",
        "development": "cross-env 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": "cross-env 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": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },

软件版本:

  • NPM:6.4.1
  • Node.js:8.12.0
  • Webpack:4.29.0
  • Laravel:5.5
  • Laravel组合:4.0.14
  • 操作系统:Ubuntu 18.04
  • PHP:7.0.30
  • Docker:18.09.1,内部版本4c52b90

package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env 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": "cross-env 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": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "@fortawesome/fontawesome-free": "^5.5.0",
        "axios": "^0.17",
        "bootstrap": "^4.1.3",
        "cross-env": "^5.1",
        "datatables": "^1.10.18",
        "datatables.net-bs4": "^1.10.19",
        "datatables.net-buttons-bs4": "^1.5.3",
        "datatables.net-plugins": "^1.10.18",
        "datatables.net-rowreorder": "^1.2.5",
        "datatables.net-rowreorder-bs4": "^1.2.5",
        "jquery": "^3.2",
        "laravel-mix": "^4.0.14",
        "popper.js": "^1.14.6",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.16.1",
        "sass-loader": "^7.1.0",
        "vue-template-compiler": "^2.5.22"
    },
    "dependencies": {
        "@babel/polyfill": "^7.2.5",
        "animate.css": "^3.7.0",
        "bootstrap4-notify": "^4.0.3",
        "dropzone": "^5.5.1",
        "jquery-mask-plugin": "^1.14.15",
        "select2": "^4.0.5",
        "toastr": "^2.1.4"
    }
}

1 个答案:

答案 0 :(得分:1)

您应该具有mix.js(),并将一些输入通过管道传送到babel。

mix.js('resources/assets/js/cart.js', 'public/js/cart.js').babel('public/js/cart.js', 'public/js/cart.js')