@playcraft/devkit 1.0.30 → 1.0.31-beta.2
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/commands/build.js +2 -10
- package/cli/commands/dev.js +1 -1
- package/cli/commands/pack.js +8 -6
- package/core/artifacts/emit.js +1 -0
- package/core/artifacts/fflate.js +1 -0
- package/core/artifacts/zip.js +1 -0
- package/core/batch-build.js +4 -4
- package/core/engines/cocos/cli-build.js +4 -0
- package/core/engines/cocos/cli.js +1 -0
- package/core/engines/cocos/constants.js +1 -0
- package/core/engines/cocos/creator-cli.js +1 -0
- package/core/engines/cocos/dev-server.js +3 -0
- package/core/engines/cocos/fs.js +1 -0
- package/core/engines/cocos/injects/3x/init.js +19 -0
- package/core/engines/cocos/injects/3x/main.js +2 -0
- package/core/engines/cocos/injects/libs/pako.js +1 -0
- package/core/engines/cocos/mcp-refresh.js +4 -0
- package/core/engines/cocos/merge.js +6 -0
- package/core/engines/cocos/pack.js +1 -0
- package/core/engines/cocos/preview-concat.js +8 -0
- package/core/engines/cocos/preview-concat.test.js +1 -0
- package/core/engines/cocos/preview-json-hook.js +1 -0
- package/core/engines/cocos/preview-json-pack.js +5 -0
- package/core/engines/cocos/preview-json-pack.test.js +2 -0
- package/core/engines/cocos/strip-social-share.js +7 -0
- package/core/engines/cocos/theme-assets.js +3 -0
- package/core/engines/web/index.js +1 -0
- package/core/engines/web/vite.dev.js +32 -0
- package/core/engines/web/webpack.build.js +80 -0
- package/core/engines/web/webpack.common.js +11 -0
- package/core/engines/web/webpack.dev.js +16 -0
- package/core/index.d.ts +52 -0
- package/core/index.js +1 -1
- package/core/injectors/apply.js +1 -0
- package/core/injectors/check-channel-matrix.js +9 -0
- package/core/injectors/spec.js +107 -0
- package/core/options.js +6 -5
- package/core/utils/mergeOptions.js +1 -1
- package/core/utils/parseArgvOptions.js +2 -2
- package/core/vite.dev.js +1 -32
- package/core/webpack.build.js +1 -81
- package/core/webpack.common.js +1 -11
- package/core/webpack.dev.js +1 -16
- package/package.json +4 -1
package/core/webpack.build.js
CHANGED
|
@@ -1,81 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
* HtmlWebpackPlugin beforeEmit 钩子。
|
|
3
|
-
* 在最终 HTML 输出前统一修正 meta 标签:
|
|
4
|
-
* - charset → 统一小写 utf-8
|
|
5
|
-
* - viewport → 统一替换为渠道通道规范值
|
|
6
|
-
* 项目模板无需关心 meta 标签,全部由 devkit 构建时自动处理。
|
|
7
|
-
*/class MetaTagOverridePlugin{constructor(adNetwork){this.adNetwork=adNetwork}apply(compiler){compiler.hooks.compilation.tap("MetaTagOverridePlugin",compilation=>{HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tap("MetaTagOverridePlugin",data=>{// charset: 统一小写
|
|
8
|
-
data.html=data.html.replace(/<meta\s+charset=["'][^"']*["']\s*\/?>/i,"<meta charset=\"utf-8\" />");// viewport: Mintegral 需要 minimum-scale,其他渠道通用
|
|
9
|
-
const viewportContent=this.adNetwork==="mintegral"?META.MINTEGRAL_VIEWPORT:META.COMMON_VIEWPORT;data.html=data.html.replace(/<meta\s+name=["']viewport["'][^>]*\/?>/i,`<meta name="viewport" content="${viewportContent}" />`);// font-family: Liftoff 渠道需要指定系统字体
|
|
10
|
-
if(this.adNetwork==="liftoff"){const fontStyle=FontFamily.LIFTOFF;data.html=data.html.replace("</head>",fontStyle+"</head>")}return data})})}}/** @type {AD_NETWORK[]} *//** @type {AD_NETWORK[]} */const zipOutputNetworks=["google","pangle","tiktok","vungle","mytarget","mintegral","adikteev","bigabid","inmobi",// InMobi 支持 ZIP 格式(包含 index.html + 资源文件)
|
|
11
|
-
"snapchat","bigoads","liftoff","facebook",// Facebook:ZIP 内仅 index.html(JS 全部内联),上限 5MB
|
|
12
|
-
"remerge"// Remerge Rich Media:ZIP + index.html + mraid.js
|
|
13
|
-
];/** @type {AD_NETWORK[]} */const zipOutputAllowedNetworks=["moloco"];/**
|
|
14
|
-
* Creates webpack configuration for production build
|
|
15
|
-
* @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
|
|
16
|
-
* @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
|
|
17
|
-
* @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
|
|
18
|
-
* @returns {import('webpack').Configuration} Final webpack production configuration
|
|
19
|
-
*/function makeWebpackBuildConfig(customOptions,customDefines,webpackCustomConfig){const buildOptions=mergeOptions(options,customOptions);logOptions(buildOptions);customDefines=customDefines||{};webpackCustomConfig=webpackCustomConfig||{};/** @type {AD_NETWORK} */const adNetwork=buildOptions["network"];/** @type {AD_PROTOCOL} */const adProtocol=buildOptions["protocol"];/** @type {'both'|'landscape'|'portrait'} 当前单次构建实际使用的横竖屏方向版本,默认 'both' */const playcraftOrientationValue=buildOptions.playcraftOrientationValue||"both";/** @type {string} 方向版本对应的命名后缀:landscape→'_L',portrait→'_P',both→'' */const orientationSuffix=getPlaycraftOrientationSuffix(playcraftOrientationValue);/** @type {string} 渠道 + 方向后缀组成的产物标识,如 'google_L' */const outputId=`${adNetwork}${orientationSuffix}`;let outDir=buildTemplateString(buildOptions.outDir,buildOptions);function getFileName(){let filename=buildTemplateString(buildOptions.filename,buildOptions);if(adNetwork==="mintegral")return filename.replace(/\s+/g,"").replace(/[^a-zA-Z0-9]/g,"_").replace("_fullhash_6_","[fullhash:6]");return filename}const isZipOutput=zipOutputNetworks.includes(adNetwork)||buildOptions.zip&&zipOutputAllowedNetworks.includes(adNetwork);const{isChannelFold2Zip,isZipOutputFinal}=resolveChannelFold2Zip({isChannelFold2ZipOption:buildOptions.isChannelFold2Zip,adNetwork,isZipOutput});let htmlFileName="";if(adNetwork==="mintegral")htmlFileName="index.html";// 修改为 index.html
|
|
20
|
-
else if(isZipOutputFinal)htmlFileName="index.html";else htmlFileName=`${getFileName()}.html`;const metaTags={viewport:META.COMMON_VIEWPORT};if(adNetwork==="mintegral"){metaTags["viewport"]=META.MINTEGRAL_VIEWPORT}if(!buildOptions.skipRecommendedMeta){metaTags["HandheldFriendly"]="True";metaTags["cleartype"]={"http-equiv":"cleartype",content:"on"};metaTags["apple-mobile-web-app-capable"]="yes";metaTags["mobile-web-app-capable"]="yes";metaTags["X-UA-Compatible"]={"http-equiv":"X-UA-Compatible",content:"IE=10"}}let htmlWebpackPluginConfig={template:path.resolve("src/index.html"),filename:htmlFileName,title:`${buildOptions.name} - ${buildOptions.app}`,inlineSource:".(js|css|png|jpg|webp|svg|xml|atlas|mp3|gif|glb|fbx|obj)$",meta:metaTags};if(adNetwork==="adikteev")htmlWebpackPluginConfig=generateAdikteevHtmlWebpackPluginConfig("src/index.html");else if(adNetwork==="bigabid")htmlWebpackPluginConfig=generateBigabidHtmlWebpackPluginConfig("src/index.html");else if(adNetwork==="inmobi")htmlWebpackPluginConfig=generateInMobiHtmlWebpackPluginConfig("src/index.html",buildOptions);const webpackConfig=merge(webpackCommonConfig,{mode:"production",stats:"errors-only",optimization:{usedExports:true,minimize:(buildOptions.obfuscateLevel!==undefined?buildOptions.obfuscateLevel:2)>=1,minimizer:[new TerserPlugin({extractComments:false,terserOptions:{safari10:true,mangle:{reserved:["$"],// ⚠️ 不要开启 properties: true,会混淆 Phaser 等框架的属性名导致运行时错误
|
|
21
|
-
// properties: true,
|
|
22
|
-
toplevel:true},compress:{drop_console:true,arrows:false,drop_debugger:true,unused:true,dead_code:true,// 🔥 增加优化轮数
|
|
23
|
-
passes:3,// 🔥 激进压缩选项
|
|
24
|
-
inline:3,// 最大内联
|
|
25
|
-
collapse_vars:true,// 折叠变量
|
|
26
|
-
reduce_vars:true,// 减少变量
|
|
27
|
-
hoist_vars:true,// 提升变量
|
|
28
|
-
hoist_funs:true,// 提升函数
|
|
29
|
-
sequences:20,// 更长的序列化
|
|
30
|
-
properties:true,// 优化属性访问
|
|
31
|
-
conditionals:true,// 优化条件
|
|
32
|
-
comparisons:true,// 优化比较
|
|
33
|
-
booleans:true,// 优化布尔
|
|
34
|
-
loops:true,// 优化循环
|
|
35
|
-
if_return:true,// 优化 if-return
|
|
36
|
-
join_vars:true,// 合并变量
|
|
37
|
-
negate_iife:true,// 否定 IIFE
|
|
38
|
-
side_effects:true,// 移除副作用
|
|
39
|
-
switches:true,// 优化 switch
|
|
40
|
-
typeofs:true,// 优化 typeof
|
|
41
|
-
unsafe:false,// 不使用 unsafe(避免破坏框架)
|
|
42
|
-
keep_fargs:false,// 移除未使用参数
|
|
43
|
-
drop_console:true},output:{comments:false,quote_style:3,beautify:false,wrap_iife:true,ecma:2015},toplevel:true,keep_classnames:false,keep_fnames:false}})]},plugins:[new HtmlWebpackPlugin(htmlWebpackPluginConfig),new MetaTagOverridePlugin(adNetwork),// 注入 window.playcraftOrientation 全局变量,标识当前构建产物对应的横竖屏方向版本
|
|
44
|
-
new PlaycraftOrientationInjectorPlugin(playcraftOrientationValue),new webpack.DefinePlugin({...buildDefines(buildOptions),...buildOptions.defines,...customDefines}),// For some reason needed for PIXI v8
|
|
45
|
-
new webpack.optimize.LimitChunkCountPlugin({maxChunks:1})]},webpackCustomConfig);webpackConfig.output.path=path.resolve(outDir);// 根据混淆等级注入 obfuscator loader
|
|
46
|
-
const obfuscateLevel=buildOptions.obfuscateLevel!==undefined?buildOptions.obfuscateLevel:2;// 获取需要排除压缩的目录列表
|
|
47
|
-
const excludeCompressDirs=buildOptions.excludeCompressDirs||[];if(obfuscateLevel>=2){// 构建各等级的 obfuscator 配置
|
|
48
|
-
const obfuscatorOptions={// 通用基础配置
|
|
49
|
-
target:"browser",sourceMap:false,selfDefending:false,renameProperties:false,disableConsoleOutput:true,splitStrings:false,unicodeEscapeSequence:false};if(obfuscateLevel===2){// 等级2:基础混淆(控制流平坦化 + 字符串数组)
|
|
50
|
-
Object.assign(obfuscatorOptions,{controlFlowFlattening:true,controlFlowFlatteningThreshold:0.75,deadCodeInjection:false,stringArray:true,stringArrayThreshold:0.75,stringArrayEncoding:["base64"],stringArrayIndexShift:true,stringArrayRotate:true,stringArrayShuffle:true,stringArrayWrappersCount:2,stringArrayWrappersChainedCalls:true,stringArrayWrappersType:"function",stringArrayCallsTransform:true,stringArrayCallsTransformThreshold:0.75,transformObjectKeys:true,identifierNamesGenerator:"hexadecimal"})}else if(obfuscateLevel===3){// 等级3:在等级2基础上增加死代码注入
|
|
51
|
-
Object.assign(obfuscatorOptions,{controlFlowFlattening:true,controlFlowFlatteningThreshold:0.75,deadCodeInjection:true,deadCodeInjectionThreshold:0.4,stringArray:true,stringArrayThreshold:0.75,stringArrayEncoding:["base64"],stringArrayIndexShift:true,stringArrayRotate:true,stringArrayShuffle:true,stringArrayWrappersCount:2,stringArrayWrappersChainedCalls:true,stringArrayWrappersType:"function",stringArrayCallsTransform:true,stringArrayCallsTransformThreshold:0.75,transformObjectKeys:true,identifierNamesGenerator:"hexadecimal"})}else if(obfuscateLevel===4){// 等级4:最高强度混淆
|
|
52
|
-
Object.assign(obfuscatorOptions,{controlFlowFlattening:true,controlFlowFlatteningThreshold:1,deadCodeInjection:true,deadCodeInjectionThreshold:0.5,stringArray:true,stringArrayThreshold:1,stringArrayEncoding:["rc4"],stringArrayIndexShift:true,stringArrayRotate:true,stringArrayShuffle:true,stringArrayWrappersCount:3,stringArrayWrappersChainedCalls:true,stringArrayWrappersType:"function",stringArrayCallsTransform:true,stringArrayCallsTransformThreshold:1,transformObjectKeys:true,identifierNamesGenerator:"hexadecimal",splitStrings:true,splitStringsChunkLength:5,unicodeEscapeSequence:true})}console.log(`Obfuscation level: ${obfuscateLevel} (${["","terser-only","basic","dead-code","maximum"][obfuscateLevel]})`);// 构建exclude数组,包含node_modules和用户指定的排除目录
|
|
53
|
-
const excludePatterns=[];if(excludeCompressDirs.length>0){excludeCompressDirs.forEach(dir=>{excludePatterns.push(path.resolve(dir))});console.log(`ℹ️ Excluding directories from compression: ${excludeCompressDirs.join(", ")}`)}webpackConfig.module.rules.push({test:/\.(js|ts)$/,include:[path.resolve("src")],exclude:excludePatterns,enforce:"post",use:{loader:require.resolve("webpack-obfuscator/dist/loader"),options:obfuscatorOptions}})}else if(obfuscateLevel===1){console.log("Obfuscation level: 1 (terser-only)")}else{console.log("Obfuscation level: 0 (no minimize/obfuscate)")}// Adikteev 需要单独提取 CSS 为 style.css,替换默认的 style-loader
|
|
54
|
-
if(adNetwork==="adikteev"){const cssRuleIndex=webpackConfig.module.rules.findIndex(rule=>rule.test&&rule.test.toString().includes("\\.css"));if(cssRuleIndex!==-1){webpackConfig.module.rules[cssRuleIndex]={test:/\.css$/,use:[MiniCssExtractPlugin.loader,"css-loader"]};console.log("\u2705 Adikteev: CSS will be extracted to style.css")}}// 决定是否内联 JS 到 HTML
|
|
55
|
-
// 以下渠道需要分离 JS 文件,不使用 HtmlInlineScriptPlugin:
|
|
56
|
-
// - mintegral: 需要独立的 JS 文件
|
|
57
|
-
// - adikteev: 需要 creative.js 上传到 CDN
|
|
58
|
-
// - bigabid: 需要 main.js 上传到 CDN
|
|
59
|
-
// Facebook ZIP 只要单文件 index.html,JS 必须内联
|
|
60
|
-
if(adNetwork!=="mintegral"&&adNetwork!=="adikteev"&&adNetwork!=="bigabid")webpackConfig.plugins.push(new HtmlInlineScriptPlugin);// 注入渠道 SDK 插件(公共逻辑)
|
|
61
|
-
injectSDKPlugins(webpackConfig,{network:adNetwork,protocol:adProtocol,playcraftOrientationValue});if(isZipOutputFinal){if(adNetwork==="tiktok"){webpackConfig.plugins.push(new CopyWebpackPlugin({patterns:[{from:path.join(__dirname,"resources","tiktok-config.json"),to:"config.json"}]}))}else if(adNetwork==="snapchat"){const tmpConfigPath=path.join(__dirname,"resources","snapchat-config.json");webpackConfig.plugins.push(new CopyWebpackPlugin({patterns:[{from:tmpConfigPath,to:"config.json"}]}))}else if(adNetwork==="bigoads"){// BigoAds 要求输出 ZIP 包,包含 index.html 和 config.json
|
|
62
|
-
// SDK 注入已在 injectSDKPlugins 中处理
|
|
63
|
-
webpackConfig.plugins.push(new CopyWebpackPlugin({patterns:[{from:path.join(__dirname,"resources","bigoads-config.json"),to:"config.json"}]}))}webpackConfig.plugins.push(new ZipPlugin({filename:isChannelFold2Zip?outputId:getFileName(),path:path.resolve(outDir),cleanTempFolder:true,// 🗑️ 生成 zip 后删除临时文件夹
|
|
64
|
-
// Facebook:zip 内只保留内联后的 index.html,不要带上 build.js
|
|
65
|
-
...(adNetwork==="facebook"?{include:/(?:^|\/)index\.html$/}:{})}));webpackConfig.output.path=path.resolve(outDir,outputId);if(adNetwork==="adikteev"){webpackConfig.output.filename="creative.js";// Adikteev 需要将 CSS 单独提取为 style.css 文件
|
|
66
|
-
webpackConfig.plugins.push(new MiniCssExtractPlugin({filename:"style.css"}))}else if(adNetwork==="bigabid")webpackConfig.output.filename="main.js";else if(adNetwork==="inmobi")webpackConfig.output.filename="main.js"}// 添加 fflate 压缩插件(仅在打正式包时生效)
|
|
67
|
-
if(buildOptions.fflateCompression){console.log("\u2705 fflate compression enabled (production build only)");webpackConfig.plugins.push(new FflateCompressionPlugin({enabled:true,level:9,keepOriginal:false,logStats:true,googlePlayUrl:buildOptions.googlePlayUrl,appStoreUrl:buildOptions.appStoreUrl}))}return webpackConfig}/**
|
|
68
|
-
* Runs webpack production build
|
|
69
|
-
* @param {import('webpack').Configuration} [webpackConfig] - Webpack configuration to use, creates default if not provided
|
|
70
|
-
* @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
|
|
71
|
-
* @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
|
|
72
|
-
* @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
|
|
73
|
-
*/function runBuild(webpackConfig,customOptions,customDefines,webpackCustomConfig){return new Promise((resolve,reject)=>{if(!webpackConfig)webpackConfig=makeWebpackBuildConfig(customOptions,customDefines,webpackCustomConfig);const compiler=webpack(webpackConfig);// 必须显式调用 compiler.close() 释放本次编译占用的内存(模块图/资源缓存/
|
|
74
|
-
// Terser 与 obfuscator 等插件持有的引用)。webpack 官方要求:若在同一进程内
|
|
75
|
-
// 多次调用 compiler.run(),每次 run 完成后都要 close,否则上一次编译的内存
|
|
76
|
-
// 无法被回收。playcraftOrientationChannel 会在同一进程里串行构建多个方向
|
|
77
|
-
// 版本(多次调用本函数),若不 close,内存会随构建次数线性累加,最终触发
|
|
78
|
-
// "JavaScript heap out of memory"。
|
|
79
|
-
const finalize=error=>{compiler.close(closeErr=>{if(closeErr){console.error("\u5173\u95ED webpack compiler \u65F6\u51FA\u9519:",closeErr)}if(error){reject(error)}else{resolve()}})};compiler.run((err,stats)=>{if(err){console.error("Build failed:",err.stack||err);if(err.details){console.error("Error details:",err.details)}return finalize(err)}if(stats.hasErrors()){const errors=stats.compilation.errors;console.error(`\n❌ Build finished with ${errors.length} error(s):\n`);// 打印每个错误的详细信息
|
|
80
|
-
errors.forEach((error,index)=>{console.error(`\n[Error ${index+1}/${errors.length}]`);console.error(error.message||error);if(error.stack){console.error(error.stack)}});// 拒绝 Promise 时传递格式化的错误消息
|
|
81
|
-
const errorMessage=errors.map((e,i)=>`[${i+1}] ${e.message||e}`).join("\n");finalize(new Error(`Webpack build failed with ${errors.length} error(s):\n${errorMessage}`))}else{console.log(`Build successful!`);finalize(null)}})})}exports.makeWebpackBuildConfig=makeWebpackBuildConfig;exports.runBuild=runBuild;
|
|
1
|
+
"use strict";module.exports=require("./engines/web/webpack.build.js");
|
package/core/webpack.common.js
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
+
"use strict";module.exports=require("./engines/web/webpack.common.js");
|
package/core/webpack.dev.js
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
* Creates webpack configuration for development
|
|
3
|
-
* @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
|
|
4
|
-
* @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
|
|
5
|
-
* @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
|
|
6
|
-
* @returns {import('webpack').Configuration} Final webpack development configuration
|
|
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}/**
|
|
11
|
-
* Starts webpack development server
|
|
12
|
-
* @param {import('webpack').Configuration} [webpackConfig] - Webpack configuration to use, creates default if not provided
|
|
13
|
-
* @param {Partial<import('./index').CLIOptions>} [customOptions] - Custom options to merge with default options
|
|
14
|
-
* @param {Record<string, any>} [customDefines] - Additional defines for webpack.DefinePlugin
|
|
15
|
-
* @param {import('webpack').Configuration} [webpackCustomConfig] - Custom webpack config to merge
|
|
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;
|
|
1
|
+
"use strict";module.exports=require("./engines/web/webpack.dev.js");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playcraft/devkit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.31-beta.2",
|
|
4
4
|
"description": "HTML5 Playable Ads 构建工具,支持多广告渠道打包",
|
|
5
5
|
"main": "core/index.js",
|
|
6
6
|
"module": "core/index.js",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"@vue/compiler-sfc": "^3.4.0",
|
|
28
28
|
"ajv": "^8.18.0",
|
|
29
29
|
"babel-loader": "^9.2.1",
|
|
30
|
+
"cheerio": "^1.0.0-rc.12",
|
|
30
31
|
"copy-webpack-plugin": "^13.0.0",
|
|
31
32
|
"cos-nodejs-sdk-v5": "^2.14.4",
|
|
32
33
|
"cross-spawn": "^7.0.3",
|
|
@@ -37,7 +38,9 @@
|
|
|
37
38
|
"html-webpack-plugin": "^5.6.0",
|
|
38
39
|
"json5": "^2.2.3",
|
|
39
40
|
"json5-loader": "^4.0.0",
|
|
41
|
+
"mime-types": "^2.1.35",
|
|
40
42
|
"mini-css-extract-plugin": "^2.7.6",
|
|
43
|
+
"pako": "^2.2.0",
|
|
41
44
|
"prettyjson": "^1.2.5",
|
|
42
45
|
"style-loader": "^4.0.0",
|
|
43
46
|
"tencentcloud-sdk-nodejs-cdn": "^4.1.161",
|