@playcraft/devkit 1.0.28 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/bin/playable-scripts.js +6 -44
- package/cli/commands/build.js +40 -220
- package/cli/commands/builds.js +2 -13
- package/cli/commands/dev.js +1 -7
- package/cli/commands/pack.js +39 -308
- package/cli/commands/vite-dev.js +1 -7
- package/core/batch-build.js +149 -1255
- package/core/constants.js +2 -16
- package/core/cos-uploader.js +24 -286
- package/core/index.d.ts +4 -1
- package/core/index.js +7 -76
- package/core/loaders/gltf-loader.js +28 -74
- package/core/options.js +15 -326
- package/core/plugins/AdikteevInjectorPlugin.js +4 -26
- package/core/plugins/BigoAdsInjectorPlugin.js +4 -21
- package/core/plugins/DAPIInjectorPlugin.js +2 -25
- package/core/plugins/DebuggerInjectionPlugin.js +3 -31
- package/core/plugins/ExitAPIInjectorPlugin.js +3 -56
- package/core/plugins/FflateCompressionPlugin.js +40 -231
- package/core/plugins/FontInjectionWebpackPlugin.js +4 -46
- package/core/plugins/LiftoffInjectorPlugin.js +4 -26
- package/core/plugins/MRAIDInjectorPlugin.js +2 -24
- package/core/plugins/MintegralInjectorPlugin.js +2 -25
- package/core/plugins/PangleInjectorPlugin.js +2 -24
- package/core/plugins/PlaycraftOrientationInjectorPlugin.js +3 -29
- package/core/plugins/SnapchatInjectorPlugin.js +4 -26
- package/core/plugins/SocialMediaInjectorPlugin.js +7 -119
- package/core/plugins/TikTokInjectorPlugin.js +2 -24
- package/core/plugins/UnityInjectorPlugin.js +8 -37
- package/core/plugins/ZipPlugin.js +20 -138
- package/core/plugins/socialMediaVitePlugin.js +2 -108
- package/core/utils/buildDefines.js +2 -30
- package/core/utils/buildTemplateString.js +5 -39
- package/core/utils/date.js +1 -16
- package/core/utils/fontRegistry.js +13 -81
- package/core/utils/fontResolver.js +37 -335
- package/core/utils/generateAdikteevHtmlWebpackPluginConfig.js +7 -42
- package/core/utils/generateBigabidHtmlWebpackPluginConfig.js +3 -30
- package/core/utils/generateInMobiHtmlWebpackPluginConfig.js +7 -43
- package/core/utils/getPlaycraftOrientationSuffix.js +2 -9
- package/core/utils/injectSDKPlugins.js +13 -68
- package/core/utils/logOptions.js +5 -46
- package/core/utils/mergeOptions.js +2 -19
- package/core/utils/parseArgvOptions.js +5 -111
- package/core/utils/resolveChannelFold2Zip.js +5 -17
- package/core/utils/validateThemeData.js +26 -227
- package/core/validators/pre-build-checker.js +26 -286
- package/core/validators/tracking-validator.js +40 -358
- package/core/vite.dev.js +17 -322
- package/core/webpack.build.js +66 -520
- package/core/webpack.common.js +11 -177
- package/core/webpack.dev.js +6 -88
- package/defines.d.ts +1 -0
- package/package.json +3 -4
- package/README.md +0 -262
package/core/webpack.common.js
CHANGED
|
@@ -1,177 +1,11 @@
|
|
|
1
|
-
const path = require(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} else if (fs.existsSync(jsConfigPath)) {
|
|
13
|
-
jsTsConfigPath = jsConfigPath;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** @type {string[]} List of file extensions that webpack will resolve */
|
|
17
|
-
const allowedExtensions = [
|
|
18
|
-
'.vue',
|
|
19
|
-
'.ts',
|
|
20
|
-
'.tsx',
|
|
21
|
-
'.js',
|
|
22
|
-
'.json',
|
|
23
|
-
'.json5',
|
|
24
|
-
'.png',
|
|
25
|
-
'.glb',
|
|
26
|
-
'.fbx',
|
|
27
|
-
'.obj',
|
|
28
|
-
'.jpg',
|
|
29
|
-
'.webp',
|
|
30
|
-
'.mp3',
|
|
31
|
-
'.svg',
|
|
32
|
-
'.xml',
|
|
33
|
-
'.atlas',
|
|
34
|
-
'.fnt',
|
|
35
|
-
'.css',
|
|
36
|
-
'.gif',
|
|
37
|
-
'.mp4',
|
|
38
|
-
'.woff',
|
|
39
|
-
'.woff2',
|
|
40
|
-
'.ttf',
|
|
41
|
-
'.otf'
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
/** @type {import('webpack').Configuration} Base webpack configuration used by both development and build configs */
|
|
45
|
-
const webpackConfig = {
|
|
46
|
-
entry: path.resolve('src/index'),
|
|
47
|
-
resolve: {
|
|
48
|
-
extensions: allowedExtensions,
|
|
49
|
-
alias: {
|
|
50
|
-
assets: path.resolve('assets'),
|
|
51
|
-
vue: 'vue/dist/vue.esm-bundler.js',
|
|
52
|
-
'@': path.resolve('src'),
|
|
53
|
-
},
|
|
54
|
-
plugins: jsTsConfigPath
|
|
55
|
-
? [
|
|
56
|
-
new TsconfigPathsPlugin({
|
|
57
|
-
configFile: jsTsConfigPath,
|
|
58
|
-
extensions: allowedExtensions
|
|
59
|
-
})
|
|
60
|
-
]
|
|
61
|
-
: []
|
|
62
|
-
},
|
|
63
|
-
output: {
|
|
64
|
-
filename: 'build.js',
|
|
65
|
-
path: path.resolve('dist')
|
|
66
|
-
},
|
|
67
|
-
module: {
|
|
68
|
-
rules: [
|
|
69
|
-
// Vue 单文件组件
|
|
70
|
-
{
|
|
71
|
-
test: /\.vue$/,
|
|
72
|
-
loader: 'vue-loader'
|
|
73
|
-
},
|
|
74
|
-
// {
|
|
75
|
-
// test: /\.tsx?$/,
|
|
76
|
-
// use: 'ts-loader',
|
|
77
|
-
// exclude: /node_modules/,
|
|
78
|
-
// },
|
|
79
|
-
{
|
|
80
|
-
test: /\.ts?$/,
|
|
81
|
-
exclude: /node_modules/,
|
|
82
|
-
use: [
|
|
83
|
-
{
|
|
84
|
-
loader: 'babel-loader',
|
|
85
|
-
options: {
|
|
86
|
-
// presets: ['@babel/preset-env'],
|
|
87
|
-
plugins:
|
|
88
|
-
options.compilation.allowTemplateLiterals === false ? ['@babel/plugin-transform-template-literals'] : []
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
{
|
|
93
|
-
loader: 'esbuild-loader',
|
|
94
|
-
options: {
|
|
95
|
-
loader: 'ts',
|
|
96
|
-
target: 'es2015'
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
]
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
test: /\.css$/,
|
|
103
|
-
use: ['style-loader', 'css-loader']
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
test: /\.(js|mjs)$/,
|
|
107
|
-
// exclude: /node_modules/,
|
|
108
|
-
use: {
|
|
109
|
-
loader: 'babel-loader',
|
|
110
|
-
options: {
|
|
111
|
-
// presets: ['@babel/preset-env'],
|
|
112
|
-
plugins: options.compilation.allowTemplateLiterals === false ? ['@babel/plugin-transform-template-literals'] : []
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
test: /\.(gltf)$/,
|
|
118
|
-
loader: path.join(__dirname, 'loaders/gltf-loader.js')
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
test: /\.(gif|png|jpe?g|webp|mp3|mp4|m4a|ogg|wav|glb|fbx|obj)$/i,
|
|
122
|
-
type: 'asset/inline'
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
test: /\.json5$/i,
|
|
126
|
-
type: 'javascript/auto',
|
|
127
|
-
use: {
|
|
128
|
-
loader: 'json5-loader',
|
|
129
|
-
options: {
|
|
130
|
-
esModule: false
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
// 处理 json?url → base64
|
|
135
|
-
{
|
|
136
|
-
test: /\.json$/i,
|
|
137
|
-
resourceQuery: /url/,
|
|
138
|
-
type: 'asset/inline',
|
|
139
|
-
generator: {
|
|
140
|
-
dataUrl: (content) => `data:application/json;base64,${content.toString('base64')}`
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
test: /\.(svg|xml)$/i,
|
|
145
|
-
type: 'asset/source'
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
test: /\.atlas$/,
|
|
149
|
-
type: 'asset/inline',
|
|
150
|
-
generator: {
|
|
151
|
-
dataUrl: (content) => {
|
|
152
|
-
return `data:text/atlas;base64,${content.toString('base64')}`;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
test: /\.fnt$/i,
|
|
158
|
-
type: 'asset/inline',
|
|
159
|
-
generator: {
|
|
160
|
-
dataUrl: (content) => {
|
|
161
|
-
return `data:text/plain;base64,${content.toString('base64')}`;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
test: /\.(woff|woff2|eot|ttf|otf)$/i,
|
|
167
|
-
type: 'asset/inline'
|
|
168
|
-
}
|
|
169
|
-
]
|
|
170
|
-
},
|
|
171
|
-
plugins: [
|
|
172
|
-
new VueLoaderPlugin()
|
|
173
|
-
]
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
exports.allowedExtensions = allowedExtensions;
|
|
177
|
-
exports.webpackCommonConfig = webpackConfig;
|
|
1
|
+
"use strict";const path=require("path");const fs=require("fs");const TsconfigPathsPlugin=require("tsconfig-paths-webpack-plugin");const{VueLoaderPlugin}=require("vue-loader");const{options}=require("./options");const tsConfigPath=path.resolve(options.tsConfig);const jsConfigPath=path.resolve(options.jsConfig);let jsTsConfigPath=null;if(fs.existsSync(tsConfigPath)){jsTsConfigPath=tsConfigPath}else if(fs.existsSync(jsConfigPath)){jsTsConfigPath=jsConfigPath}/** @type {string[]} List of file extensions that webpack will resolve */const allowedExtensions=[".vue",".ts",".tsx",".js",".json",".json5",".png",".glb",".fbx",".obj",".jpg",".webp",".mp3",".svg",".xml",".atlas",".fnt",".css",".gif",".mp4",".woff",".woff2",".ttf",".otf"];/** @type {import('webpack').Configuration} Base webpack configuration used by both development and build configs */const webpackConfig={entry:path.resolve("src/index"),resolve:{extensions:allowedExtensions,alias:{assets:path.resolve("assets"),vue:"vue/dist/vue.esm-bundler.js","@":path.resolve("src")},plugins:jsTsConfigPath?[new TsconfigPathsPlugin({configFile:jsTsConfigPath,extensions:allowedExtensions})]:[]},output:{filename:"build.js",path:path.resolve("dist")},module:{rules:[// Vue 单文件组件
|
|
2
|
+
{test:/\.vue$/,loader:"vue-loader"},// {
|
|
3
|
+
// test: /\.tsx?$/,
|
|
4
|
+
// use: 'ts-loader',
|
|
5
|
+
// exclude: /node_modules/,
|
|
6
|
+
// },
|
|
7
|
+
{test:/\.ts?$/,exclude:/node_modules/,use:[{loader:"babel-loader",options:{// presets: ['@babel/preset-env'],
|
|
8
|
+
plugins:options.compilation.allowTemplateLiterals===false?["@babel/plugin-transform-template-literals"]:[]}},{loader:"esbuild-loader",options:{loader:"ts",target:"es2015"}}]},{test:/\.css$/,use:["style-loader","css-loader"]},{test:/\.(js|mjs)$/,// exclude: /node_modules/,
|
|
9
|
+
use:{loader:"babel-loader",options:{// presets: ['@babel/preset-env'],
|
|
10
|
+
plugins:options.compilation.allowTemplateLiterals===false?["@babel/plugin-transform-template-literals"]:[]}}},{test:/\.(gltf)$/,loader:path.join(__dirname,"loaders/gltf-loader.js")},{test:/\.(gif|png|jpe?g|webp|mp3|mp4|m4a|ogg|wav|glb|fbx|obj)$/i,type:"asset/inline"},{test:/\.json5$/i,type:"javascript/auto",use:{loader:"json5-loader",options:{esModule:false}}},// 处理 json?url → base64
|
|
11
|
+
{test:/\.json$/i,resourceQuery:/url/,type:"asset/inline",generator:{dataUrl:content=>`data:application/json;base64,${content.toString("base64")}`}},{test:/\.(svg|xml)$/i,type:"asset/source"},{test:/\.atlas$/,type:"asset/inline",generator:{dataUrl:content=>{return`data:text/atlas;base64,${content.toString("base64")}`}}},{test:/\.fnt$/i,type:"asset/inline",generator:{dataUrl:content=>{return`data:text/plain;base64,${content.toString("base64")}`}}},{test:/\.(woff|woff2|eot|ttf|otf)$/i,type:"asset/inline"}]},plugins:[new VueLoaderPlugin]};exports.allowedExtensions=allowedExtensions;exports.webpackCommonConfig=webpackConfig;
|
package/core/webpack.dev.js
CHANGED
|
@@ -1,98 +1,16 @@
|
|
|
1
|
-
const
|
|
2
|
-
const webpack = require('webpack');
|
|
3
|
-
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
4
|
-
const WebpackDevServer = require('webpack-dev-server');
|
|
5
|
-
const { webpackCommonConfig } = require('./webpack.common.js');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const { DebuggerInjectionPlugin } = require('./plugins/DebuggerInjectionPlugin.js');
|
|
8
|
-
const { options } = require('./options.js');
|
|
9
|
-
const { mergeOptions } = require('./utils/mergeOptions.js');
|
|
10
|
-
const { buildDefines } = require('./utils/buildDefines.js');
|
|
11
|
-
const { logOptions } = require('./utils/logOptions.js');
|
|
12
|
-
const { injectSDKPlugins } = require('./utils/injectSDKPlugins.js');
|
|
13
|
-
const { PlaycraftOrientationInjectorPlugin } = require('./plugins/PlaycraftOrientationInjectorPlugin.js');
|
|
14
|
-
|
|
15
|
-
/**
|
|
1
|
+
"use strict";const{merge}=require("webpack-merge");const webpack=require("webpack");const HtmlWebpackPlugin=require("html-webpack-plugin");const WebpackDevServer=require("webpack-dev-server");const{webpackCommonConfig}=require("./webpack.common.js");const path=require("path");const{DebuggerInjectionPlugin}=require("./plugins/DebuggerInjectionPlugin.js");const{options}=require("./options.js");const{mergeOptions}=require("./utils/mergeOptions.js");const{buildDefines}=require("./utils/buildDefines.js");const{logOptions}=require("./utils/logOptions.js");const{injectSDKPlugins}=require("./utils/injectSDKPlugins.js");const{PlaycraftOrientationInjectorPlugin}=require("./plugins/PlaycraftOrientationInjectorPlugin.js");/**
|
|
16
2
|
* Creates webpack configuration for development
|
|
17
3
|
* @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
|
|
18
4
|
* @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
|
|
19
5
|
* @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
|
|
20
6
|
* @returns {import('webpack').Configuration} Final webpack development configuration
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
customDefines = customDefines || {};
|
|
26
|
-
webpackCustomConfig = webpackCustomConfig || {};
|
|
27
|
-
|
|
28
|
-
/** @type {'both'|'landscape'|'portrait'} */
|
|
29
|
-
const playcraftOrientationValue = devOptions.playcraftOrientationValue || 'both';
|
|
30
|
-
|
|
31
|
-
const webpackConfig = merge(
|
|
32
|
-
webpackCommonConfig,
|
|
33
|
-
{
|
|
34
|
-
mode: 'development',
|
|
35
|
-
devtool: 'inline-source-map',
|
|
36
|
-
devServer: {
|
|
37
|
-
static: {
|
|
38
|
-
directory: path.resolve('dist')
|
|
39
|
-
},
|
|
40
|
-
hot: true,
|
|
41
|
-
// compress: true,
|
|
42
|
-
port: devOptions['port'],
|
|
43
|
-
allowedHosts: 'all',
|
|
44
|
-
open: devOptions['open']
|
|
45
|
-
},
|
|
46
|
-
plugins: [
|
|
47
|
-
new HtmlWebpackPlugin({
|
|
48
|
-
template: path.resolve('src/index.html'),
|
|
49
|
-
inlineSource: '.(js|css|png|jpg|webp|svg|xml|atlas|mp3|gif|glb|fbx|obj)$',
|
|
50
|
-
meta: {
|
|
51
|
-
viewport: 'width=device-width,initial-scale=1.0,viewport-fit=cover,maximum-scale=1.0,user-scalable=no'
|
|
52
|
-
}
|
|
53
|
-
}),
|
|
54
|
-
// 注入 window.playcraftOrientation 全局变量,标识当前构建产物对应的横竖屏方向版本
|
|
55
|
-
new PlaycraftOrientationInjectorPlugin(playcraftOrientationValue),
|
|
56
|
-
|
|
57
|
-
new webpack.DefinePlugin({
|
|
58
|
-
...buildDefines(devOptions),
|
|
59
|
-
...devOptions.defines,
|
|
60
|
-
__DEV__: JSON.stringify(devOptions['dev'] === undefined ? true : devOptions['dev']),
|
|
61
|
-
...customDefines
|
|
62
|
-
})
|
|
63
|
-
]
|
|
64
|
-
},
|
|
65
|
-
webpackCustomConfig
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
if (devOptions['debugger']) {
|
|
69
|
-
webpackConfig.plugins.push(new DebuggerInjectionPlugin(devOptions['debugger']));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 注入渠道 SDK 插件(与 build 保持一致)
|
|
73
|
-
injectSDKPlugins(webpackConfig, {
|
|
74
|
-
network: devOptions['network'],
|
|
75
|
-
protocol: devOptions['protocol'],
|
|
76
|
-
playcraftOrientationValue
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
return webpackConfig;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
7
|
+
*/function makeWebpackDevConfig(customOptions,customDefines,webpackCustomConfig){const devOptions=mergeOptions(options,customOptions);logOptions(devOptions);customDefines=customDefines||{};webpackCustomConfig=webpackCustomConfig||{};/** @type {'both'|'landscape'|'portrait'} */const playcraftOrientationValue=devOptions.playcraftOrientationValue||"both";const webpackConfig=merge(webpackCommonConfig,{mode:"development",devtool:"inline-source-map",devServer:{static:{directory:path.resolve("dist")},hot:true,// compress: true,
|
|
8
|
+
port:devOptions["port"],allowedHosts:"all",open:devOptions["open"]},plugins:[new HtmlWebpackPlugin({template:path.resolve("src/index.html"),inlineSource:".(js|css|png|jpg|webp|svg|xml|atlas|mp3|gif|glb|fbx|obj)$",meta:{viewport:"width=device-width,initial-scale=1.0,viewport-fit=cover,maximum-scale=1.0,user-scalable=no"}}),// 注入 window.playcraftOrientation 全局变量,标识当前构建产物对应的横竖屏方向版本
|
|
9
|
+
new PlaycraftOrientationInjectorPlugin(playcraftOrientationValue),new webpack.DefinePlugin({...buildDefines(devOptions),...devOptions.defines,__DEV__:JSON.stringify(devOptions["dev"]===undefined?true:devOptions["dev"]),...customDefines})]},webpackCustomConfig);if(devOptions["debugger"]){webpackConfig.plugins.push(new DebuggerInjectionPlugin(devOptions["debugger"]))}// 注入渠道 SDK 插件(与 build 保持一致)
|
|
10
|
+
injectSDKPlugins(webpackConfig,{network:devOptions["network"],protocol:devOptions["protocol"],playcraftOrientationValue});return webpackConfig}/**
|
|
83
11
|
* Starts webpack development server
|
|
84
12
|
* @param {import('webpack').Configuration} [webpackConfig] - Webpack configuration to use, creates default if not provided
|
|
85
13
|
* @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
|
|
86
14
|
* @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
|
|
87
15
|
* @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
|
|
88
|
-
*/
|
|
89
|
-
function runDev(webpackConfig, customOptions, customDefines, webpackCustomConfig) {
|
|
90
|
-
if (!webpackConfig) webpackConfig = makeWebpackDevConfig(customOptions, customDefines, webpackCustomConfig);
|
|
91
|
-
|
|
92
|
-
const compiler = webpack(webpackConfig);
|
|
93
|
-
const server = new WebpackDevServer(webpackConfig.devServer, compiler);
|
|
94
|
-
server.start();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
exports.makeWebpackDevConfig = makeWebpackDevConfig;
|
|
98
|
-
exports.runDev = runDev;
|
|
16
|
+
*/function runDev(webpackConfig,customOptions,customDefines,webpackCustomConfig){if(!webpackConfig)webpackConfig=makeWebpackDevConfig(customOptions,customDefines,webpackCustomConfig);const compiler=webpack(webpackConfig);const server=new WebpackDevServer(webpackConfig.devServer,compiler);server.start()}exports.makeWebpackDevConfig=makeWebpackDevConfig;exports.runDev=runDev;
|
package/defines.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playcraft/devkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "HTML5 Playable Ads 构建工具,支持多广告渠道打包",
|
|
5
5
|
"main": "core/index.js",
|
|
6
6
|
"module": "core/index.js",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"defines.d.ts"
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
|
-
"build": "node scripts/build.js",
|
|
19
18
|
"deploy": "npm run build && cd dist && npm publish --registry https://registry.npmjs.org/ --access public",
|
|
20
19
|
"deploy:beta": "npm run build && cd dist && npm publish --registry https://registry.npmjs.org/ --access public --tag beta"
|
|
21
20
|
},
|
|
@@ -81,6 +80,6 @@
|
|
|
81
80
|
"build-tool"
|
|
82
81
|
],
|
|
83
82
|
"publishConfig": {
|
|
84
|
-
"registry": "https://
|
|
83
|
+
"registry": "https://registry.npmjs.org/"
|
|
85
84
|
}
|
|
86
|
-
}
|
|
85
|
+
}
|
package/README.md
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
# @tencent/playable-scripts
|
|
2
|
-
|
|
3
|
-
HTML5 Playable Ads 构建工具,支持多广告渠道打包。
|
|
4
|
-
|
|
5
|
-
## 特性
|
|
6
|
-
|
|
7
|
-
- 🚀 **一键构建** - 轻松为不同广告渠道生成构建包
|
|
8
|
-
- ⚡ **自动优化** - 包含压缩、Tree-shaking 和死代码消除
|
|
9
|
-
- 🗜️ **fflate 压缩** - 编译时压缩,运行时解压,体积减少 40-60%
|
|
10
|
-
- 🎯 **多渠道支持** - 支持 Google Ads、Meta、AppLovin、Unity、IronSource、BigoAds 等
|
|
11
|
-
- 🎨 **主题系统** - 支持多主题批量构建
|
|
12
|
-
- 🔄 **并发构建** - 智能并发,大幅提升构建效率
|
|
13
|
-
|
|
14
|
-
## 快速开始
|
|
15
|
-
|
|
16
|
-
### 安装
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
tnpm install --save-dev @tencent/playable-scripts
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### 配置 package.json
|
|
23
|
-
|
|
24
|
-
```json
|
|
25
|
-
{
|
|
26
|
-
"scripts": {
|
|
27
|
-
"dev": "playable-scripts dev",
|
|
28
|
-
"build": "playable-scripts build",
|
|
29
|
-
"builds": "playable-scripts builds"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### 启动开发服务器
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
npm run dev # 默认预览模式
|
|
38
|
-
npm run dev bigoads # 指定渠道调试(简写)
|
|
39
|
-
npm run dev -- --network social_media # 指定渠道调试(完整参数)
|
|
40
|
-
npm run dev -- --port 8080 # 指定端口
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### 构建指定渠道
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
npm run build google # Google Ads
|
|
47
|
-
npm run build facebook # Meta
|
|
48
|
-
npm run build unity # Unity Ads
|
|
49
|
-
npm run build bigoads # BigoAds
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### 批量构建
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
npm run builds # 构建所有渠道
|
|
56
|
-
npm run builds -- -t "theme1,theme2" # 指定主题
|
|
57
|
-
npm run builds -- -c "google,facebook" # 指定渠道
|
|
58
|
-
npm run builds -- --parallel 4 # 指定并发数
|
|
59
|
-
|
|
60
|
-
# Windows PowerShell 兼容格式(推荐)
|
|
61
|
-
npm run builds -- "theme1" "google" # 位置参数:主题 渠道
|
|
62
|
-
npm run builds -- --themes="theme1,theme2" --channels="google,facebook"
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## 支持的广告渠道
|
|
66
|
-
|
|
67
|
-
| 渠道 | 命令 | 协议 |
|
|
68
|
-
|------|------|------|
|
|
69
|
-
| Preview (预览) | `preview` | none |
|
|
70
|
-
| Google Ads | `google` | none |
|
|
71
|
-
| Meta (Facebook) | `facebook` | none |
|
|
72
|
-
| AppLovin | `applovin` | mraid |
|
|
73
|
-
| Unity Ads | `unity` | mraid |
|
|
74
|
-
| IronSource | `ironsource` | mraid/dapi |
|
|
75
|
-
| TikTok / Pangle | `tiktok` | none |
|
|
76
|
-
| BigoAds | `bigoads` | bigo-mraid |
|
|
77
|
-
| Adikteev | `adikteev` | mraid |
|
|
78
|
-
| Moloco | `moloco` | none |
|
|
79
|
-
| Liftoff | `liftoff` | mraid (ZIP) |
|
|
80
|
-
| InMobi | `inmobi` | mraid |
|
|
81
|
-
| Snapchat | `snapchat` | snapchat |
|
|
82
|
-
|
|
83
|
-
## CLI 参数
|
|
84
|
-
|
|
85
|
-
| 参数 | 描述 | 默认值 |
|
|
86
|
-
|------|----------------|-----------|
|
|
87
|
-
| **广告渠道** | 目标广告渠道 | `preview` |
|
|
88
|
-
| `--out-dir` | 输出目录 | `dist` |
|
|
89
|
-
| `--obfuscate-level` | 代码混淆等级 (1-4) | `4` |
|
|
90
|
-
| `--fflate-compression` | 启用 fflate 压缩 | `true` |
|
|
91
|
-
| `--protocol` | 广告协议 | 渠道自动决定 |
|
|
92
|
-
| `--zip` | ZIP 输出结果 | `false` |
|
|
93
|
-
| `--port` | 开发服务器端口 | `3000` |
|
|
94
|
-
| `--open` | 自动打开浏览器 | `false` |
|
|
95
|
-
| `--language` | 语言代码 | `en` |
|
|
96
|
-
| `--is-channel-fold2zip ` | 所有渠道输出为 ZIP 结果 | `false` |
|
|
97
|
-
|
|
98
|
-
## 配置文件
|
|
99
|
-
|
|
100
|
-
支持两种配置文件(推荐使用 `builds.config.js`):
|
|
101
|
-
|
|
102
|
-
### builds.config.js(推荐)
|
|
103
|
-
|
|
104
|
-
```javascript
|
|
105
|
-
module.exports = {
|
|
106
|
-
// 项目基本信息
|
|
107
|
-
projectName: 'My-Game', // 可选,默认 'Phaser Game'
|
|
108
|
-
googlePlayUrl: 'https://play.google.com/...', // 可选
|
|
109
|
-
appStoreUrl: 'https://apps.apple.com/...', // 可选
|
|
110
|
-
|
|
111
|
-
// 渠道配置
|
|
112
|
-
channels: ['google', 'facebook', 'unity'], // 可选,有默认值
|
|
113
|
-
|
|
114
|
-
// 主题配置(可选)
|
|
115
|
-
themes: {
|
|
116
|
-
enabled: true, // 默认 false
|
|
117
|
-
sourceDir: 'src/theme', // 默认 'src/theme'
|
|
118
|
-
entryFile: 'src/theme/index.ts', // 默认 'src/theme/index.ts'
|
|
119
|
-
whitelist: null, // 可选,过滤函数
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
// 文件命名配置(可选)
|
|
123
|
-
naming: {
|
|
124
|
-
language: 'EN', // 默认 'EN'
|
|
125
|
-
format: '无', // 默认 '无'
|
|
126
|
-
supplier: 'AIX', // 默认 'AIX'
|
|
127
|
-
follower: 'ZQL', // 默认 'ZQL'
|
|
128
|
-
generator: null, // 可选,自定义生成函数
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
// 构建配置(可选)
|
|
132
|
-
build: {
|
|
133
|
-
outputDir: 'dist-all', // 默认 'dist-all'
|
|
134
|
-
tempDirPrefix: 'dist-temp', // 默认 'dist-temp'
|
|
135
|
-
continueOnError: true, // 默认 true
|
|
136
|
-
cleanTemp: true, // 默认 true
|
|
137
|
-
parallel: undefined, // 默认自动计算(CPU核心数-1,最小2最大8)
|
|
138
|
-
},
|
|
139
|
-
cosConfig: {
|
|
140
|
-
enabled: true, // 是否启用 COS 上传
|
|
141
|
-
SecretId: 'YOUR_SECRET_ID', // 腾讯云 SecretId
|
|
142
|
-
SecretKey: 'YOUR_SECRET_KEY', // 腾讯云 SecretKey
|
|
143
|
-
Bucket: 'your-bucket-1234567890', // COS 存储桶名称
|
|
144
|
-
Region: 'ap-guangzhou', // COS 区域
|
|
145
|
-
CdnDomain: 'your-cdn-domain.com', // CDN 域名(用于生成访问链接)
|
|
146
|
-
PathPrefix: 'playable/preview', // COS 路径前缀(可选)
|
|
147
|
-
},
|
|
148
|
-
// 打包参数(可选)
|
|
149
|
-
obfuscateLevel: 4, // 默认 4
|
|
150
|
-
fflateCompression: false, // 默认 true
|
|
151
|
-
};
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### build.json(向后兼容)
|
|
155
|
-
|
|
156
|
-
```json
|
|
157
|
-
{
|
|
158
|
-
"app": "AppName",
|
|
159
|
-
"name": "ConceptName",
|
|
160
|
-
"google_play_url": "https://play.google.com/...",
|
|
161
|
-
"app_store_url": "https://apps.apple.com/..."
|
|
162
|
-
}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### 配置优先级
|
|
166
|
-
|
|
167
|
-
```
|
|
168
|
-
命令行参数 > build.json > builds.config.js > 默认值
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
## 代码混淆等级
|
|
172
|
-
|
|
173
|
-
| 等级 | 名称 | 说明 | 体积影响 |
|
|
174
|
-
|------|------|------|----------|
|
|
175
|
-
| **1** | terser-only | 仅 Terser 压缩 | 基准 |
|
|
176
|
-
| **2** | basic | 控制流平坦化 + 字符串编码 | +5~10% |
|
|
177
|
-
| **3** | dead-code | 等级 2 + 死代码注入 | +15~25% |
|
|
178
|
-
| **4** | maximum | 全部拉满(默认) | +30~50% |
|
|
179
|
-
|
|
180
|
-
## fflate 压缩
|
|
181
|
-
|
|
182
|
-
| 指标 | 效果 |
|
|
183
|
-
|------|------|
|
|
184
|
-
| **压缩率** | 66-68% |
|
|
185
|
-
| **体积减少** | 40-60% |
|
|
186
|
-
| **解压速度** | 3-5ms |
|
|
187
|
-
| **兼容性** | 99%+ 浏览器 |
|
|
188
|
-
|
|
189
|
-
## 批量构建
|
|
190
|
-
|
|
191
|
-
### 特性
|
|
192
|
-
|
|
193
|
-
1. **智能并发** - 自动根据 CPU 核心数优化(默认:核心数-1,最小2最大8)
|
|
194
|
-
2. **独立临时目录** - 每个任务使用独立目录,避免冲突
|
|
195
|
-
3. **主题切换** - 自动切换主题入口文件
|
|
196
|
-
4. **错误容忍** - 单个失败不影响其他构建
|
|
197
|
-
|
|
198
|
-
### 命令行参数
|
|
199
|
-
|
|
200
|
-
| 参数 | 缩写 | 描述 | 示例 |
|
|
201
|
-
|------|------|------|------|
|
|
202
|
-
| `--themes` | `-t` | 指定主题列表(逗号分隔) | `-t "theme1,theme2"` |
|
|
203
|
-
| `--channels` | `-c` | 指定渠道列表(逗号分隔) | `-c "google,facebook"` |
|
|
204
|
-
| `--parallel` | `-p` | 指定并发数 | `-p 4` |
|
|
205
|
-
| 位置参数 | - | 第一个参数=主题,第二个=渠道 | `"theme1" "google"` |
|
|
206
|
-
| `=` 格式 | - | Windows PowerShell 兼容 | `--themes="theme1"` |
|
|
207
|
-
|
|
208
|
-
**注意**:
|
|
209
|
-
- **Mac/Linux**:所有格式均可使用
|
|
210
|
-
- **Windows PowerShell**:推荐使用位置参数或 `--themes=value` 格式
|
|
211
|
-
- **Windows CMD**:所有格式均可使用
|
|
212
|
-
|
|
213
|
-
### 输出结构
|
|
214
|
-
|
|
215
|
-
```
|
|
216
|
-
dist-all/
|
|
217
|
-
├── theme1/
|
|
218
|
-
│ ├── theme1_google/
|
|
219
|
-
│ │ └── theme1-EN-无-3月-20260304-AIX-ZQL-google.html
|
|
220
|
-
│ └── theme1_facebook/
|
|
221
|
-
│ └── theme1-EN-无-3月-20260304-AIX-ZQL-facebook.html
|
|
222
|
-
└── theme2/
|
|
223
|
-
└── ...
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
第二级目录名为 `主题名_渠道名`(而不是单纯的渠道名),避免不同主题下同名渠道目录混淆。
|
|
227
|
-
|
|
228
|
-
## 全局变量
|
|
229
|
-
|
|
230
|
-
构建时自动注入:
|
|
231
|
-
|
|
232
|
-
| 变量 | 描述 | 示例 |
|
|
233
|
-
|------|------|------|
|
|
234
|
-
| `__DEV__` | 开发模式标志 | `true` / `false` |
|
|
235
|
-
| `AD_NETWORK` | 当前广告渠道 | `"google"`, `"bigoads"` |
|
|
236
|
-
| `AD_PROTOCOL` | 当前广告协议 | `"none"`, `"mraid"` |
|
|
237
|
-
| `GOOGLE_PLAY_URL` | Google Play 链接 | `"https://..."` |
|
|
238
|
-
| `APP_STORE_URL` | App Store 链接 | `"https://..."` |
|
|
239
|
-
|
|
240
|
-
## 配套 SDK
|
|
241
|
-
|
|
242
|
-
配合 `@tencent/playable-sdk` 使用:
|
|
243
|
-
|
|
244
|
-
```bash
|
|
245
|
-
tnpm install @tencent/playable-sdk
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
```javascript
|
|
249
|
-
import { sdk } from '@tencent/playable-sdk';
|
|
250
|
-
|
|
251
|
-
sdk.init((width, height) => {
|
|
252
|
-
new Game(width, height);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
sdk.start(); // 游戏开始
|
|
256
|
-
sdk.finish(); // 游戏结束
|
|
257
|
-
sdk.install(); // 跳转商店
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
## 许可证
|
|
261
|
-
|
|
262
|
-
MIT License
|