我们通过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"
},
软件版本:
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"
}
}
答案 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')