mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
support compile with CC_WECHATGAME macro
This commit is contained in:
@@ -106,7 +106,7 @@ exports.buildCocosJs = function (sourceFile, outputFile, excludes, callback) {
|
||||
bundler.ignore(file);
|
||||
});
|
||||
|
||||
var uglifyOption = Utils.getUglifyOptions('build', false, true);
|
||||
var uglifyOption = Utils.getUglifyOptions('build', { debug: true });
|
||||
|
||||
bundler = bundler.bundle();
|
||||
bundler = bundler.pipe(Source(outFile));
|
||||
@@ -134,7 +134,7 @@ exports.buildCocosJsMin = function (sourceFile, outputFile, excludes, callback,
|
||||
bundler.ignore(file);
|
||||
});
|
||||
|
||||
var uglifyOption = Utils.getUglifyOptions('build', false, false);
|
||||
var uglifyOption = Utils.getUglifyOptions('build');
|
||||
|
||||
var Size = null;
|
||||
try {
|
||||
@@ -193,7 +193,7 @@ exports.buildPreview = function (sourceFile, outputFile, callback) {
|
||||
.pipe(Source(outFile))
|
||||
.pipe(Buffer())
|
||||
.pipe(Sourcemaps.init({loadMaps: true}))
|
||||
.pipe(Minify(Utils.getUglifyOptions('preview', false, false)))
|
||||
.pipe(Minify(Utils.getUglifyOptions('preview')))
|
||||
.pipe(Optimizejs({
|
||||
sourceMap: false
|
||||
}))
|
||||
@@ -224,7 +224,7 @@ exports.buildJsbPreview = function (sourceFile, outputFile, excludes, callback)
|
||||
.pipe(Source(outFile))
|
||||
.pipe(Buffer())
|
||||
.pipe(FixJavaScriptCore())
|
||||
.pipe(Minify(Utils.getUglifyOptions('preview', true, false)))
|
||||
.pipe(Minify(Utils.getUglifyOptions('preview', { jsb: true })))
|
||||
.pipe(Optimizejs({
|
||||
sourceMap: false
|
||||
}))
|
||||
@@ -250,7 +250,7 @@ exports.buildJsb = function (sourceFile, outputFile, excludes, callback) {
|
||||
.pipe(Source(outFile))
|
||||
.pipe(Buffer())
|
||||
.pipe(FixJavaScriptCore())
|
||||
.pipe(Minify(Utils.getUglifyOptions('build', true, true)))
|
||||
.pipe(Minify(Utils.getUglifyOptions('build', { jsb: true, debug: true })))
|
||||
.pipe(Optimizejs({
|
||||
sourceMap: false
|
||||
}))
|
||||
@@ -276,7 +276,7 @@ exports.buildJsbMin = function (sourceFile, outputFile, excludes, callback) {
|
||||
.pipe(Source(outFile))
|
||||
.pipe(Buffer())
|
||||
.pipe(FixJavaScriptCore())
|
||||
.pipe(Minify(Utils.getUglifyOptions('build', true, false)))
|
||||
.pipe(Minify(Utils.getUglifyOptions('build', { jsb: true })))
|
||||
.pipe(Optimizejs({
|
||||
sourceMap: false
|
||||
}))
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ exports.build = function (sourceFile, outputFile, sourceFileForExtends, outputFi
|
||||
}
|
||||
|
||||
// remove `...args` used in CC_JSB
|
||||
engine = engine.pipe(Minify(Utils.getUglifyOptions('test', false, false)));
|
||||
engine = engine.pipe(Minify(Utils.getUglifyOptions('test')));
|
||||
|
||||
if (sourcemaps) {
|
||||
engine = engine.pipe(Sourcemaps.write('./', {
|
||||
|
||||
+30
-9
@@ -1,29 +1,50 @@
|
||||
|
||||
const PLATFORM_MACROS = ['CC_EDITOR', 'CC_PREVIEW', 'CC_BUILD', 'CC_TEST'];
|
||||
const FLAGS = ['jsb', 'wechatgame', 'debug'];
|
||||
|
||||
// generate macros for uglify's global_defs
|
||||
// platform: editor | preview | build | test
|
||||
exports.getMacros = function (platform, isJSB, isDebugBuild) {
|
||||
// available platforms: 'editor' | 'preview' | 'build' | 'test'
|
||||
// available keys of flags: 'jsb' | 'wechatgame' | 'debug'
|
||||
exports.getMacros = function (platform, flags) {
|
||||
// platform macros
|
||||
var platformMacro = 'CC_' + platform.toUpperCase();
|
||||
if (PLATFORM_MACROS.indexOf(platformMacro) === -1) {
|
||||
throw new Error('Unknown platform: ' + platform);
|
||||
}
|
||||
var res = {};
|
||||
for (var i = 0; i < PLATFORM_MACROS.length; i++) {
|
||||
var macro = PLATFORM_MACROS[i];
|
||||
for (let i = 0; i < PLATFORM_MACROS.length; i++) {
|
||||
let macro = PLATFORM_MACROS[i];
|
||||
res[macro] = (macro === platformMacro);
|
||||
}
|
||||
|
||||
// flag macros
|
||||
if (flags) {
|
||||
for (let flag in flags) {
|
||||
if (flags.hasOwnProperty(flag) && flags[flag]) {
|
||||
if (FLAGS.indexOf(flag) === -1) {
|
||||
throw new Error('Unknown flag: ' + flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < FLAGS.length; i++) {
|
||||
let flag = FLAGS[i];
|
||||
let macro = 'CC_' + flag.toUpperCase();
|
||||
res[macro] = !!(flags && flags[flag]);
|
||||
}
|
||||
|
||||
// debug macros
|
||||
res['CC_DEV'] = res['CC_EDITOR'] || res['CC_PREVIEW'] || res['CC_TEST'];
|
||||
res['CC_DEBUG'] = res['CC_DEV'] || !!isDebugBuild;
|
||||
res['CC_JSB'] = !!isJSB;
|
||||
res['CC_DEBUG'] = res['CC_DEBUG'] || res['CC_DEV'];
|
||||
console.log(res);
|
||||
return res;
|
||||
};
|
||||
|
||||
exports.getUglifyOptions = function (platform, isJSB, isDebugBuild) {
|
||||
var global_defs = exports.getMacros(platform, isJSB, isDebugBuild);
|
||||
exports.getUglifyOptions = function (platform, flags) {
|
||||
var global_defs = exports.getMacros(platform, flags);
|
||||
var releaseMode = !global_defs['CC_DEBUG'];
|
||||
|
||||
var optimizeForJSC = releaseMode && isJSB;
|
||||
var optimizeForJSC = releaseMode && global_defs['CC_JSB'];
|
||||
if (optimizeForJSC) {
|
||||
return {
|
||||
output: {
|
||||
|
||||
Reference in New Issue
Block a user