[add] 熱更新
This commit is contained in:
44
packages/hot-update/main.js
Normal file
44
packages/hot-update/main.js
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
var Fs = require("fire-fs");
|
||||
var Path = require("fire-path");
|
||||
|
||||
module.exports = {
|
||||
load: function () {
|
||||
// 当 package 被正确加载的时候执行
|
||||
},
|
||||
|
||||
unload: function () {
|
||||
// 当 package 被正确卸载的时候执行
|
||||
},
|
||||
|
||||
messages: {
|
||||
'editor:build-finished': function (event, target) {
|
||||
var root = Path.normalize(target.dest);
|
||||
var url = Path.join(root, "main.js");
|
||||
Fs.readFile(url, "utf8", function (err, data) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
var newStr =
|
||||
"(function () { \n"+
|
||||
"\n"+
|
||||
" if (cc.sys.isNative) { \n" +
|
||||
" var hotUpdateSearchPaths = cc.sys.localStorage.getItem('HotUpdateSearchPaths'); \n" +
|
||||
" if (hotUpdateSearchPaths) { \n" +
|
||||
" jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths)); \n" +
|
||||
" }\n" +
|
||||
" }";
|
||||
|
||||
var newData = data.replace("(function () {", newStr);
|
||||
Fs.writeFile(url, newData, function (error) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
Editor.log("SearchPath updated in built main.js for hot update");
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
7
packages/hot-update/package.json
Normal file
7
packages/hot-update/package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "hot-update",
|
||||
"version": "0.0.1",
|
||||
"description": "用于热更新插件",
|
||||
"author": "Cocos Creator",
|
||||
"main": "main.js"
|
||||
}
|
Reference in New Issue
Block a user