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",
"watch": "webpack --config ./webpack.config.js --watch",
"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"
},
"keywords": [],

View File

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

View File

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

View File

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

View File

@ -1,5 +1,21 @@
const path = require('path');
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 = {
entry: {

View File

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

View File

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

View File

@ -36,6 +36,7 @@ import {
updateShouldUpdateOfTree
} from './vnode/VNodeShouldUpdate';
import { getPathArr } from './utils/vNodePath';
import { injectUpdater } from '../external/devtools';
// 不可恢复错误
let unrecoverableErrorDuringBuild: any = null;
@ -281,6 +282,11 @@ function renderFromRoot(treeRoot) {
if (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.send(treeRoot);
}