@playcraft/devkit 1.0.19 → 1.0.21

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