我正在使用npm脚本(请参阅下面的我的npm文件)来查看watchify
更改的文件,然后在编译后进行编译和通知。然而,发生的事情是watchify任务运行(首次运行时需要40秒),然后立即调用notify:js
任务。我希望在watchify完成编译后调用notify:js
。
{
"dependencies": {
"react": "^0.14.3",
"react-dom": "^0.14.3"
},
"devDependencies": {
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"babelify": "^7.2.0",
"browserify": "^12.0.1",
"exorcist": "^0.4.0",
"osx-notifier": "^0.2.2",
"watchify": "^3.6.1"
},
"scripts": {
"watch": "watchify src/app.js -o build/bundle.js -t [ babelify --presets [ es2015 react ] ] -dv | npm run notify:js",
"compile:js": "browserify -e src/app.js -d -o build/bundle.js -t [ babelify --presets [ es2015 react ] ] -v",
"notify:js": "osx-notifier --title 'JavaScript Compiled' --message 'JavaScript compiled to build/bundle.js' --type pass"
}
}
我尝试了以下命令变体。
watchify src/app.js -o build/bundle.js -t [ babelify --presets [ es2015 react ] ] \
-dv & npm run notify:js
上述命令与|
运算符相同。
watchify src/app.js -o build/bundle.js -t [ babelify --presets [ es2015 react ] ] \
-dv && npm run notify:js
上述命令与&
运算符相同。
我无法在watchify documentation中看到我想要实现的任何选项。我在这里遗漏了什么,或者我试图这样做是不可能的?
答案 0 :(得分:3)
我使用nodemon和browserify-incremental解决了这个问题。
这会将JavaScript编译为bundle.js
文件。
browserifyinc -e resources/assets/js/app.js -o public/assets/js/bundle.js --cachefile .browserify-cache.json && npm run notify:js
这是我的package.json
文件。
{
"dependencies": {
"react": "^0.14.3",
"react-dom": "^0.14.3"
},
"devDependencies": {
"babelify": "^6.1.3",
"browserify": "^12.0.1",
"browserify-incremental": "^3.0.1",
"nodemon": "^1.3.8"
},
"browserify": {
"transform": [
"babelify"
]
},
"scripts": {
"build": "npm run compile:js && npm run compile:sass",
"watch": "npm run watch:js & npm run watch:sass",
"notify:js": "osascript -e 'display notification \"JavaScript compiled to public/assets/js/bundle.js\" with title \"JavaScript Compiled\"'",
"notify:sass": "osascript -e 'display notification \"CSS compiled to public/assets/js/app.js\" with title \"CSS Compiled\"'",
"compile:js": "browserifyinc -e resources/assets/js/app.js -o public/assets/js/bundle.js --cachefile .browserify-cache.json && npm run notify:js",
"compile:sass": "sass resources/assets/sass/app.scss:public/assets/css/app.css && npm run notify:sass",
"watch:js": "nodemon --watch 'resources/assets/js' --exec 'npm run compile:js'",
"watch:sass": "nodemon --watch 'resources/assets/sass' -e scss --exec 'npm run compile:sass'"
}
}