mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
refine uglify’s macro
This commit is contained in:
+6
-31
@@ -25,7 +25,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
const Utils = require('./utils');
|
||||
const Utils = require('../util/utils');
|
||||
const Path = require('path');
|
||||
|
||||
const Source = require('vinyl-source-stream');
|
||||
@@ -48,12 +48,7 @@ exports.buildCocosJs = function (sourceFile, outputFile, excludes, callback) {
|
||||
bundler.ignore(file);
|
||||
});
|
||||
|
||||
var uglifyOption = Utils.uglifyOptions(false, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: true,
|
||||
CC_TEST: false,
|
||||
CC_JSB: false
|
||||
});
|
||||
var uglifyOption = Utils.uglifyOptions('build', false, true);
|
||||
|
||||
bundler = bundler.bundle();
|
||||
bundler = bundler.pipe(Source(outFile));
|
||||
@@ -81,12 +76,7 @@ exports.buildCocosJsMin = function (sourceFile, outputFile, excludes, callback,
|
||||
bundler.ignore(file);
|
||||
});
|
||||
|
||||
var uglifyOption = Utils.uglifyOptions(true, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: false,
|
||||
CC_TEST: false,
|
||||
CC_JSB: false
|
||||
});
|
||||
var uglifyOption = Utils.uglifyOptions('build', false, false);
|
||||
|
||||
var Size = null;
|
||||
try {
|
||||
@@ -145,12 +135,7 @@ exports.buildPreview = function (sourceFile, outputFile, callback) {
|
||||
.pipe(Source(outFile))
|
||||
.pipe(Buffer())
|
||||
.pipe(Sourcemaps.init({loadMaps: true}))
|
||||
.pipe(Minifier(Utils.uglifyOptions(false, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: true,
|
||||
CC_TEST: false,
|
||||
CC_JSB: false
|
||||
}), UglifyHarmony))
|
||||
.pipe(Minifier(Utils.uglifyOptions('preview', false, false), UglifyHarmony))
|
||||
.pipe(Optimizejs({
|
||||
sourceMap: false
|
||||
}))
|
||||
@@ -176,12 +161,7 @@ exports.buildJsb = function (sourceFile, outputFile, jsbSkipModules, callback) {
|
||||
.pipe(HandleErrors())
|
||||
.pipe(Source(outFile))
|
||||
.pipe(Buffer())
|
||||
.pipe(Minifier(Utils.uglifyOptions(false, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: false, // CC_DEV should be false after build
|
||||
CC_TEST: false,
|
||||
CC_JSB: true
|
||||
}), UglifyHarmony))
|
||||
.pipe(Minifier(Utils.uglifyOptions('build', true, true), UglifyHarmony))
|
||||
.pipe(Optimizejs({
|
||||
sourceMap: false
|
||||
}))
|
||||
@@ -202,12 +182,7 @@ exports.buildJsbMin = function (sourceFile, outputFile, jsbSkipModules, callback
|
||||
.pipe(HandleErrors())
|
||||
.pipe(Source(outFile))
|
||||
.pipe(Buffer())
|
||||
.pipe(Minifier(Utils.uglifyOptions(true, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: false,
|
||||
CC_TEST: false,
|
||||
CC_JSB: true
|
||||
}), UglifyHarmony))
|
||||
.pipe(Minifier(Utils.uglifyOptions('build', true, false), UglifyHarmony))
|
||||
.pipe(Optimizejs({
|
||||
sourceMap: false
|
||||
}))
|
||||
|
||||
+2
-7
@@ -40,7 +40,7 @@ const Minifier = require('gulp-uglify/minifier');
|
||||
const Sourcemaps = require('gulp-sourcemaps');
|
||||
const UglifyHarmony = require('uglify-js-harmony');
|
||||
|
||||
const Utils = require('./utils');
|
||||
const Utils = require('../util/utils');
|
||||
|
||||
exports.build = function (sourceFile, outputFile, sourceFileForExtends, outputFileForExtends, callback) {
|
||||
var engine = Utils.createBundler(sourceFile)
|
||||
@@ -51,12 +51,7 @@ exports.build = function (sourceFile, outputFile, sourceFileForExtends, outputFi
|
||||
.pipe(Buffer())
|
||||
// remove `..args` used in CC_JSB
|
||||
.pipe(Sourcemaps.init({loadMaps: true}))
|
||||
.pipe(Minifier(Utils.uglifyOptions(false, {
|
||||
CC_EDITOR: false,
|
||||
CC_DEV: true,
|
||||
CC_TEST: true,
|
||||
CC_JSB: false
|
||||
}), UglifyHarmony))
|
||||
.pipe(Minifier(Utils.uglifyOptions('test', false, false), UglifyHarmony))
|
||||
.pipe(Sourcemaps.write('./', {
|
||||
sourceRoot: '../',
|
||||
includeContent: false,
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// generate macros for uglify's global_defs
|
||||
|
||||
var PLATFORM_MACROS = ['CC_EDITOR', 'CC_PREVIEW', 'CC_BUILD', 'CC_TEST'];
|
||||
|
||||
// platform: editor | preview | build | test
|
||||
module.exports = function (platform, isJSB, isDebugBuild) {
|
||||
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];
|
||||
res[macro] = (macro === platformMacro);
|
||||
}
|
||||
res['CC_DEV'] = res['CC_EDITOR'] || res['CC_PREVIEW'] || res['CC_TEST'];
|
||||
res['CC_DEBUG'] = res['CC_DEV'] || !!isDebugBuild;
|
||||
res['CC_JSB'] = !!isJSB;
|
||||
return res;
|
||||
};
|
||||
@@ -4,12 +4,14 @@ const Path = require('path');
|
||||
allowReturnOutsideFunctionInBrowserifyTransform();
|
||||
const Browserify = require('browserify');
|
||||
const Fs = require('fs');
|
||||
const Macro = require('./macro');
|
||||
|
||||
const preludePath = Path.resolve(__dirname, '../browserify_prelude.js');
|
||||
const prelude = Fs.readFileSync(preludePath, 'utf8');
|
||||
|
||||
exports.uglifyOptions = function (minify, global_defs) {
|
||||
if (minify) {
|
||||
exports.uglifyOptions = function (platform, isJSB, isDebugBuild) {
|
||||
var global_defs = Macro(platform, isJSB, isDebugBuild);
|
||||
if (!global_defs['CC_DEBUG']) {
|
||||
return {
|
||||
compress: {
|
||||
global_defs: global_defs,
|
||||
Reference in New Issue
Block a user