Match-id-80dac32ce407402ccfcdaf71a197c4f53d3cac98

This commit is contained in:
* 2022-05-13 09:49:35 +08:00 committed by *
commit 7f2f2a8746
8 changed files with 32 additions and 8 deletions

View File

@ -7,7 +7,7 @@
"build": "webpack --config ./webpack.config.js", "build": "webpack --config ./webpack.config.js",
"watch": "webpack --config ./webpack.config.js --watch", "watch": "webpack --config ./webpack.config.js --watch",
"build-dev": "webpack --config ./webpack.dev.js", "build-dev": "webpack --config ./webpack.dev.js",
"start": "webpack serve --config ./webpack.dev.js ", "start": "npm run build && webpack serve --config ./webpack.dev.js ",
"test": "jest" "test": "jest"
}, },
"keywords": [], "keywords": [],

View File

@ -51,6 +51,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
changeSource(message, DevToolBackground); changeSource(message, DevToolBackground);
connections[tabId].postMessage(message); connections[tabId].postMessage(message);
} else { } else {
// TODO: 如果查询失败,发送 chrome message请求 panel 主动建立连接
console.log('Tab not found in connection list.'); console.log('Tab not found in connection list.');
} }
} else { } else {

View File

@ -134,6 +134,7 @@ let helper;
function init(horizonHelper) { function init(horizonHelper) {
helper = horizonHelper; helper = horizonHelper;
window.__HORIZON_DEV_HOOK__.isInit = true;
} }
function injectHook() { function injectHook() {
@ -144,6 +145,7 @@ function injectHook() {
enumerable: false, enumerable: false,
value: { value: {
init, init,
isInit: false,
addIfNotInclude, addIfNotInclude,
send, send,
deleteVNode, deleteVNode,

View File

@ -1,10 +1,8 @@
<!doctype html> <!doctype html>
<html> <html style="display: flex">
<head> <head>
<meta charset="utf8"> <meta charset="utf8">
<title>Horizon</title>
<script src='horizon.production.js'></script>
<style> <style>
html { html {
width: 100%; width: 100%;
@ -24,11 +22,12 @@
} }
</style> </style>
<script src='horizon.development.js'></script>
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>
<script src="panel.js"></script>
</body> </body>
</html> </html>

View File

@ -1,5 +1,21 @@
const path = require('path'); const path = require('path');
const webpack = require('webpack'); const webpack = require('webpack');
const fs = require('fs');
function handleBuildDir() {
const staticDir = path.join(__dirname, 'build');
console.log('staticDir: ', staticDir);
const isBuildExist = fs.existsSync(staticDir);
console.log('isBuildExist: ', isBuildExist);
if (!isBuildExist) {
fs.mkdirSync(staticDir);
}
fs.copyFileSync(path.join(__dirname, 'src', 'panel', 'panel.html'),path.join(staticDir, 'panel.html'));
fs.copyFileSync(path.join(__dirname, 'src', 'main', 'main.html'),path.join(staticDir, 'main.html'));
fs.copyFileSync(path.join(__dirname, 'src', 'manifest.json'),path.join(staticDir, 'manifest.json'));
}
handleBuildDir();
const config = { const config = {
entry: { entry: {

View File

@ -47,7 +47,7 @@ module.exports = {
}, },
devServer: { devServer: {
static: { static: {
directory: path.join(__dirname, 'dist'), directory: path.join(__dirname, 'build'),
}, },
open: 'panel.html', open: 'panel.html',
port: 9000, port: 9000,

View File

@ -74,7 +74,7 @@ export const helper = {
}, },
}; };
function injectUpdater() { export function injectUpdater() {
const hook = window.__HORIZON_DEV_HOOK__; const hook = window.__HORIZON_DEV_HOOK__;
if (hook) { if (hook) {
hook.init(helper); hook.init(helper);

View File

@ -36,6 +36,7 @@ import {
updateShouldUpdateOfTree updateShouldUpdateOfTree
} from './vnode/VNodeShouldUpdate'; } from './vnode/VNodeShouldUpdate';
import { getPathArr } from './utils/vNodePath'; import { getPathArr } from './utils/vNodePath';
import { injectUpdater } from '../external/devtools';
// 不可恢复错误 // 不可恢复错误
let unrecoverableErrorDuringBuild: any = null; let unrecoverableErrorDuringBuild: any = null;
@ -281,6 +282,11 @@ function renderFromRoot(treeRoot) {
if (window.__HORIZON_DEV_HOOK__) { if (window.__HORIZON_DEV_HOOK__) {
const hook = window.__HORIZON_DEV_HOOK__; const hook = window.__HORIZON_DEV_HOOK__;
// injector.js 可能在 Horizon 代码之后加载,此时无 __HORIZON_DEV_HOOK__ 全局变量
// Horizon 代码初次加载时不会初始化 helper
if (!hook.isInit) {
injectUpdater();
}
hook.addIfNotInclude(treeRoot); hook.addIfNotInclude(treeRoot);
hook.send(treeRoot); hook.send(treeRoot);
} }