[BUG] Automatic recompile and auto-refresh preview

[BUG] Automatic recompile and auto-refresh preview
0.0 0


If you use the internal editor, make a change to a JS file, and hit save, Cocos Creator will recompile, and if you’ve checked the preference “Should Auto-refresh Preview,” the browser window will automatically refresh.

But if you use an External Script Editor (for instance the official one, Visual Studio Code), this doesn’t work. When you change a JS file and hit save, it will not automatically trigger a recompile until Cocos Creator gets focus again.

Maybe this isn’t a bug, maybe this is just a feature you haven’t implemented yet. But I think this should be an option at least. The automatic recompile and auto-refresh preview with the internal editor is really awesome.


Thanks for your feedback!
Now Creator is not support automatically recompile & refresh if it does not have focus. We will improve it if it’s feasible.

But I think this should be an option at least.

Could you please supply more details about the option? I can’t understand it. Thanks!


We will try to solve this issue by adding command line compile for Creator, this way we can link this command to external script editors. But auto-refresh browser may not work in this condition, you’ll need to hit F5 yourself after recompiled.


Could you please supply more details about the option? I can’t understand it. Thanks!

In Preferences, there’s an option called Should Auto-refresh Preview. I’m suggesting another option in Data Editor called Auto-recompile when saved in External Script Editor.

@nantas2, it says AssetDB Watch State: watch-on when it does not have focus. Doesn’t that watch allow Cocos Creator to know if a file was changed externally? A command-line compile and F5 in the browser is probably not easier than switching focus to Cocos for a second.


As I mentioned before, it’s not support Auto-recompile when saved in External Scrip Editor. So, it’s meaningless to add the option in Editor preference window. We will consider to add it once it’s supported. Thanks for your feedback!


Is this worked on? This would be a huge improvement to work with Cocos Creator. I have to constantly tab to Cocos Creator for a millisecond and then back to Visual Studio Code to get my changes applied. I think you all know what I’m talking about.

Just a simple asset file watcher in Cocos Creator should handle this just like a normal Webpack och similar script watches for file changes and re-compiles.

Anyone have figured out a smart hacky-way to solve this?


here’s a node script i used for a project

http://192.168.xxx.xxx could also just be localhost.

var Watcher = require('watch-fs').Watcher;
var curl = require('curl');

var watcher = new Watcher({
    paths: [ '../assets/'],
    filters: {
        includeFile: function(name) {
            return /\.ts$/.test(name);

var options = {};
var isUpdateable = true;

function updateDB () {
    if (!isUpdateable) {
    console.log('UPDATE DB');
    isUpdateable = false;
    curl.get('http://192.168.xxx.xxx:7456/update-db', options, function(err, response, body) {});
    setTimeout(canUpdate, 2000);

function canUpdate() {
    isUpdateable = true;

watcher.on('create', function(name) {
    console.log('file ' + name + ' created');

watcher.on('change', function(name) {
    console.log('file ' + name + ' changed');

watcher.on('delete', function(name) {
    console.log('file ' + name + ' deleted');

watcher.start(function(err, failed) {
    console.log('watcher started');
    console.log('files not found', failed);


Amazing @phero_constructs! Works like a charm! :sunny: Thank you so much for sharing :slight_smile:


No problem!

You should probably change the title to [SOLVED]


@Howrad Created this thread so I guess he has to mark it as [SOLVED].

Cocos Creator could of course also integrate this into their editor by default.


Creator has no longer a default editor.


That’s true, I read about it after writing that comment. I’m quite confused about it and curious what their plan is.


I posted this in July 2016, and I guess I kind of got over this problem. As a project gets larger and larger, compile time increases, and I didn’t want an automatic recompile every time I saved. However, this script would still be useful sometimes, thank you!

Do you mean that Cocos Creator no longer has an internal editor? Or is Visual Studio Code no longer the official editor?


Actually, both are correct.