gpt4 book ai didi

node.js - Node 脚本 : Chaining commands with watchify

转载 作者:搜寻专家 更新时间:2023-10-31 23:47:23 27 4
gpt4 key购买 nike

我正在使用 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 中看不到任何选项为了我想要实现的目标。我在这里遗漏了什么或者我尝试这样做的方式不可能吗?

最佳答案

我使用 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'"
}
}

关于node.js - Node 脚本 : Chaining commands with watchify,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34042530/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com