可以在这里看看项目链接https://github.com/ppgee/cocos-pnp哈,里面包括导出核心包和 Cocos 插件,里面还有之前为 Cocos 适配淘宝小程序的插件。
Support exporting playable ads for the cocos plugin and node.js
XMLHttpRequest
from single html passing the platform test>= 2.4.6 | 3.6.x |
---|---|
Latest ✅ | Latest ✅ |
platform / version | >= 2.4.6 | 3.6.x |
---|---|---|
AppLovin | ✅ | ✅ |
✅ | ✅ | |
✅ | ✅ | |
IronSource | ✅ | ✅ |
Liftoff | ✅ | ✅ |
Mintegral | ✅ | ✅ |
Moloco | ✅ | ✅ |
Pangle | ✅ | ✅ |
Rubeex | ✅ | ✅ |
Tiktok | ✅ | ✅ |
Unity | ✅ | ✅ |
Using npm:
$ npm install playable-adapter-core
Using yarn:
$ yarn add playable-adapter-core
Using pnpm:
$ pnpm install playable-adapter-core
import {
TPlatform,
exec2xAdapter,
} from "playable-adapter-core";
const main = async () => {
const config = {
buildFolderPath: "/your/build/folder/path",
adapterRC: {
buildPlatform: "web-mobile",
exportChannels: "Facebook",
injectOptions: {
Facebook: {},
},
orientation: "auto",
skipBuild: true,
tinify: true,
tinifyApiKey: "your tinify api key",
},
};
// required
const version = "2"; // '2' | '3'
version === "2"
? await exec2xAdapter(config)
: await exec3xAdapter(config);
};
main();
npm install safeify
import { Api, useContext } from "@midwayjs/hooks";
import { Context } from "@midwayjs/koa";
import {
TPlatform,
exec2xAdapter,
exec3xAdapter,
} from "playable-adapter-core";
import { Safeify } from "safeify";
export const uploadBuildPkg = Api(Upload(), async () => {
const ctx = useContext<Context>();
// 调用接口
const files = useFiles();
const fields = useFields() as UploadFields;
const buildPkgKey = Object.keys(files).pop();
const buildPkg = <
{
data: string;
fieldName: string;
filename: string;
mimeType: string;
_ext: string;
}
>files[buildPkgKey].pop();
const buildChannels = JSON.parse(fields.channels ?? "[]") as TChannel[];
const tinify = JSON.parse(fields.tinify ?? "false") as boolean;
const tinifyApiKey = fields.tinifyApiKey ?? "";
const injectOptions = JSON.parse(fields.injectOptions ?? "{}") as {
[key in TChannel]: TChannelRC;
};
const webOrientation = fields.webOrientation ?? "auto";
const version = fields.version ?? "2";
const zipFilePath = buildPkg.data;
const zipExt = buildPkg._ext;
const filename = buildPkg.filename.replaceAll(buildPkg._ext, "") as TPlatform;
const unzipDir = join(
dirname(buildPkg.data),
basename(zipFilePath).replace(zipExt, "")
);
const config = {
buildFolderPath: unzipDir,
adapterBuildConfig: {
buildPlatform: filename,
exportChannels: buildChannels,
injectOptions,
orientation: webOrientation,
skipBuild: true,
tinify,
tinifyApiKey
},
}
// 创建 safeify 实例
const safeVm = new Safeify({
timeout: 3000,
asyncTimeout: 120000,
unrestricted: true,
});
await safeVm.run(
`
version === '2'
? await exec2xAdapter(config)
: await exec3xAdapter(config)
`,
{
version,
exec2xAdapter,
exec3xAdapter,
config,
}
);
return true;
});
'{{__adv_channels_adapter__}}'
support dynamic import from cocos source code, just like:
// source code
window.advChannels = "{{__adv_channels_adapter__}}"; // 防止 rollup 打包进行 tree-shaking 省略掉该代码( dead code ),占位符变量可挂载在全局
// 在 Facebook 渠道下代码会被替换为
window.advChannels = "Facebook";
exportChannels
export package from target platforms
const exportChannels: TChannel[] = ['Facebook', 'Google']
injectOptions
inject script in building html
type TChannel =
| "AppLovin"
| "Facebook"
| "Google"
| "IronSource"
| "Liftoff"
| "Mintegral"
| "Moloco"
| "Pangle"
| "Rubeex"
| "Tiktok"
| "Unity";
const injectOptions: {
[key in TChannel]: {
head: string; // 在 html 的 head 标签内尾部追加
body: string; // 在 html 的 body 标签内,且在所有 script 前追加
sdkScript: string; // 在渠道对应地方注入 sdk 脚本
};
} = {};
let config = {
tinify: true, // compress resource before build package
tinifyApiKey: '', // tinify api key, visit to https://tinypng.com/developers
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.