我想为我的chrome扩展重新加载每次我保存在扩展文件夹中的文件,而不必显式点击“重新加载”在chrome://extensions/。这可能吗?
编辑:我知道我可以更新Chrome重新加载扩展的间隔,这是一个中途的解决方案,但我宁愿让我的编辑器(emacs或textmate)触发保存重新加载或要求Chrome监控目录的变化。
我想为我的chrome扩展重新加载每次我保存在扩展文件夹中的文件,而不必显式点击“重新加载”在chrome://extensions/。这可能吗?
编辑:我知道我可以更新Chrome重新加载扩展的间隔,这是一个中途的解决方案,但我宁愿让我的编辑器(emacs或textmate)触发保存重新加载或要求Chrome监控目录的变化。
当前回答
作者推荐该webpack插件的下一个版本:https://github.com/rubenspgcavalcante/webpack-extension-reloader。这对我来说很有效。
其他回答
苹果只
使用扩展Reloader:
使用打印稿
将你的观察者添加到你的项目中:yarn Add tsc-watch 向package.json添加脚本命令
...
"scripts": {
"dev": "tsc-watch --onSuccess \"open -a '/Applications/Google Chrome.app' 'http://reload.extensions'\""
},
...
运行脚本yarn dev
使用JavaScript
将你的watcher添加到你的项目中:yarn Add watch-cli 向package.json添加脚本命令
...
"scripts": {
"dev": "watch -p \"**/*.js\" -c \"open -a '/Applications/Google Chrome.app' 'http://reload.extensions'\""
},
...
运行脚本yarn dev
额外的好处:在Extensions Reloader选项中打开“reload current tab”,这样它就会在做出更改后重新加载:
在任何场合或事件中
chrome.runtime.reload();
将重新加载您的扩展(docs)。您还需要更改舱单。Json文件,添加:
...
"permissions": [ "management" , ...]
...
如果你有一台Mac,最简单的方法就是使用Alfred App!
只需使用Powerpack获取Alfred App,然后添加下面链接中提供的工作流,并自定义你想要的热键(我喜欢使用⌘+ + R)。
现在,每次你使用热键,谷歌Chrome浏览器将重新加载,无论你在那个时刻的应用程序。
如果你想使用其他浏览器,打开AppleScript在阿尔弗雷德首选工作流程和替换“谷歌Chrome”与“Firefox”,“Safari”,…
我还将在这里显示在ReloadChrome中使用的/usr/bin/osascript脚本的内容。Alfredworkflow文件,这样你就可以看到它在做什么。
tell application "Google Chrome"
activate
delay 0.5
tell application "System Events" to keystroke "r" using command down
delay 0.5
tell application "System Events" to keystroke tab using command down
end tell
工作流文件为ReloadChrome.alfredworkflow。
我想一夜之间重新加载(更新)我的扩展,这是我在background.js中使用的:
var d = new Date();
var n = d.getHours();
var untilnight = (n == 0) ? 24*3600000 : (24-n)*3600000;
// refresh after 24 hours if hour = 0 else
// refresh after 24-n hours (that will always be somewhere between 0 and 1 AM)
setTimeout(function() {
location.reload();
}, untilnight);
问候, 彼得
使用npm init创建一个包。Json在根目录下
NPM install——save-dev gulp-open &&
然后创建gulpfile.js
它看起来像:
/* File: gulpfile.js */
// grab our gulp packages
var gulp = require('gulp'),
open = require('gulp-open');
// create a default task and just log a message
gulp.task('default', ['watch']);
// configure which files to watch and what tasks to use on file changes
gulp.task('watch', function() {
gulp.watch('extensionData/userCode/**/*.js', ['uri']);
});
gulp.task('uri', function(){
gulp.src(__filename)
.pipe(open({uri: "http://reload.extensions"}));
});
这适用于我开发CrossRider,你可能会观察改变路径,你看文件在,也假设你有npm和节点安装。