cocos构建插件不执行

求问各位,构建日志里只输出了’onAfterBuild’没有输出’onBeforeDeploy’,是什么原因,下面是npm run build之后从hook.js里面复制出来的代码。感觉是根本没编译进cocos里面。

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.onAfterMake = exports.onBeforeMake = exports.onError = exports.unload = exports.onAfterBuild = exports.onBeforeBuild = exports.load = exports.throwError = void 0;
const global_1 = require("./global");
function log(...arg) {
    return console.log(`[${global_1.PACKAGE_NAME}] `, ...arg);
}
exports.throwError = true;
const load = async function () {
    log(`Load cocos plugin in builder.`);
};
exports.load = load;
const onBeforeBuild = async function (options, result) {
    // TODO some thing
    log(`${global_1.PACKAGE_NAME}.webTestOption`, 'onBeforeBuild');
};
exports.onBeforeBuild = onBeforeBuild;
const onAfterBuild = async function (options, result) {
    if (!options.deployAfterBuild) {
        return;
    }
    log('onAfterBuild');
    log('onBeforeDeploy');
};
exports.onAfterBuild = onAfterBuild;
const unload = async function () {
    log(`Unload cocos plugin in builder.`);
};
exports.unload = unload;
const onError = async function (options, result) {
    // Todo some thing
    log(`${global_1.PACKAGE_NAME} run onError`);
};
exports.onError = onError;
const onBeforeMake = async function (root, options) {
    log(`onBeforeMake: root: ${root}, options: ${options}`);
};
exports.onBeforeMake = onBeforeMake;
const onAfterMake = async function (root, options) {
    log(`onAfterMake: root: ${root}, options: ${options}`);
};
exports.onAfterMake = onAfterMake;

还有为什么cocos论坛粘贴出来的东西要多一行换行我也是服了……

救救孩子吧,随便改一行代码插件就再也跑不通了,改回去之后重新npm run build也跑不通了。也没地方报错。


我本地测试是ok的, 你npm run build 后,需要重启项目,才能生效。

我执行了npm run build,没用……这是我的builder.ts
import { BuildPlugin, IBuildPluginConfig, IDisplayOptions } from ‘…/@types’;
function createDeployAfterBuildConfig(): IDisplayOptions {
return {
deployAfterBuild: {
label: ‘构建完成后部署’,
description: ‘启用后,构建完成将自动部署’,
default: true,
render: {
ui: ‘ui-checkbox’,
},
},
};
}
function createRemoveRemoteConfig(): IDisplayOptions {
return {
removeRemote: {
label: ‘构建后清理远程包’,
description: ‘启用后,构建后将自动清理远程包’,
default: true,
render: {
ui: ‘ui-checkbox’,
},
},
};
}
function createCommonConfig(otherOptions: IDisplayOptions[]): IBuildPluginConfig {
const commonConfig: IDisplayOptions = {
buildEnv: {
label: 构建环境,
description: 构建环境,
default: ‘test’,
render: {
ui: ‘ui-select’,
items: [
{ label: ‘Local’, value: ‘local’ },
{ label: ‘Test’, value: ‘test’ },
{ label: ‘Staging’, value: ‘staging’ },
{ label: ‘Production’, value: ‘prod’ },
],
},
},
};
for (const options of otherOptions) {
Object.assign(commonConfig, options);
}
return {
hooks: ‘./hooks’,
panel: ‘./panel’,
options: commonConfig,
};
}
export const configs: BuildPlugin.Configs = {
‘web-mobile’: createCommonConfig([
createDeployAfterBuildConfig()
]),
‘wechatgame’: createCommonConfig([
createRemoveRemoteConfig(),
createDeployAfterBuildConfig()
]),
};

cocos论坛的粘贴代码真他妈难用

Panel.ts

'use strict';
import { ICustomPanelThis, ITaskOptions } from '../@types';
import { PACKAGE_NAME } from './global';
let panel: ICustomPanelThis;
export const style = ``;
export const template = `
<div class="build-plugin">
    <ui-prop>
        <ui-label slot="label" value="Hide Link"></ui-label>
        <ui-checkbox slot="content"></ui-checkbox>
    </ui-prop>
    <ui-prop id="link">
        <ui-label slot="label" value="Docs"></ui-label>
        <ui-link slot="content" value=${Editor.Utils.Url.getDocUrl('editor/publish/custom-build-plugin.html')}></ui-link>
    </ui-prop>
</div>
`;
export const $ = {
    root: '.build-plugin',
    hideLink: 'ui-checkbox',
    link: '#link',
};
/**
 * all change of options dispatched will enter here
 * @param options
 * @param key
 * @returns
 */
export async function update(options: ITaskOptions, key: string) {
    if (key) {
        return;
    }
    // when import build options, key will bey ''
    init();
}

export function ready(options: ITaskOptions) {
    // @ts-ignore
    panel = this as ICustomPanelThis;
    panel.options = options;
    init();
}
export function close() {
    panel.$.hideLink.removeEventListener('change', onHideLinkChange);
}
function init() {
    panel.$.hideLink.value = panel.options.hideLink;
    updateLink();
    panel.$.hideLink.addEventListener('change', onHideLinkChange);
}

function onHideLinkChange(event: any) {
    panel.options.hideLink = event.target.value;
    // Note: dispatch the change to build panel
    panel.dispatch('update', `packages.${PACKAGE_NAME}.hideLink`, panel.options.hideLink);
    updateLink();
}

function updateLink() {
    if (panel.options.hideLink) {
        panel.$.link.style.display = 'none';
    } else {
        panel.$.link.style.display = 'block';
    }
}