mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
optimize unit-test compile time
This commit is contained in:
+34
-16
@@ -23,6 +23,8 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
const GEN_SOURCE_MAPS = false;
|
||||
|
||||
'use strict';
|
||||
|
||||
const Path = require('path');
|
||||
@@ -43,31 +45,47 @@ const UglifyHarmony = require('uglify-js-harmony');
|
||||
const Utils = require('../util/utils');
|
||||
|
||||
exports.build = function (sourceFile, outputFile, sourceFileForExtends, outputFileForExtends, callback) {
|
||||
var engine = Utils.createBundler(sourceFile)
|
||||
var cacheDir = Path.resolve(Path.dirname(outputFile), '.cache/test-compile-cache');
|
||||
var engine = Utils.createBundler(sourceFile, {
|
||||
sourcemaps: GEN_SOURCE_MAPS,
|
||||
cacheDir: cacheDir
|
||||
})
|
||||
.bundle()
|
||||
.on('error', HandleErrors.handler)
|
||||
.pipe(HandleErrors())
|
||||
.pipe(Source(Path.basename(outputFile)))
|
||||
.pipe(Buffer())
|
||||
// remove `..args` used in CC_JSB
|
||||
.pipe(Sourcemaps.init({loadMaps: true}))
|
||||
.pipe(Minifier(Utils.uglifyOptions('test', false, false), UglifyHarmony))
|
||||
.pipe(Sourcemaps.write('./', {
|
||||
.pipe(Buffer());
|
||||
|
||||
if (GEN_SOURCE_MAPS) {
|
||||
engine = engine.pipe(Sourcemaps.init({loadMaps: true}));
|
||||
}
|
||||
|
||||
// remove `..args` used in CC_JSB
|
||||
engine = engine.pipe(Minifier(Utils.uglifyOptions('test', false, false), UglifyHarmony));
|
||||
|
||||
if (GEN_SOURCE_MAPS) {
|
||||
engine = engine.pipe(Sourcemaps.write('./', {
|
||||
sourceRoot: '../',
|
||||
includeContent: false,
|
||||
addComment: true
|
||||
}))
|
||||
//
|
||||
.pipe(Gulp.dest(Path.dirname(outputFile)));
|
||||
}));
|
||||
}
|
||||
|
||||
engine = engine.pipe(Gulp.dest(Path.dirname(outputFile)));
|
||||
|
||||
if (Fs.existsSync(sourceFileForExtends)) {
|
||||
var engineExtends = Utils.createBundler(sourceFileForExtends, {
|
||||
presets: ['env'],
|
||||
ast: false,
|
||||
babelrc: false,
|
||||
highlightCode: false,
|
||||
sourceMaps: true,
|
||||
compact: false
|
||||
var engineExtends = Utils.createBundler(sourceFileForExtends,
|
||||
{
|
||||
sourcemaps: GEN_SOURCE_MAPS,
|
||||
babelifyOpt: {
|
||||
presets: ['env'],
|
||||
ast: false,
|
||||
babelrc: false,
|
||||
highlightCode: false,
|
||||
sourceMaps: true,
|
||||
compact: false
|
||||
},
|
||||
cacheDir: cacheDir
|
||||
})
|
||||
.bundle()
|
||||
.on('error', HandleErrors.handler)
|
||||
|
||||
+26
-6
@@ -2,7 +2,6 @@
|
||||
|
||||
const Path = require('path');
|
||||
allowReturnOutsideFunctionInBrowserifyTransform();
|
||||
const Browserify = require('browserify');
|
||||
const Fs = require('fs');
|
||||
const Macro = require('./macro');
|
||||
|
||||
@@ -103,10 +102,15 @@ function allowReturnOutsideFunctionInBrowserifyTransform () {
|
||||
}
|
||||
}
|
||||
|
||||
exports.createBundler = function createBundler(entryFiles, babelifyOpt) {
|
||||
/*
|
||||
* @param [options.sourcemaps = true]
|
||||
* @param [options.babelifyOpt]
|
||||
*/
|
||||
exports.createBundler = function createBundler(entryFiles, options) {
|
||||
// https://github.com/substack/node-browserify#methods
|
||||
var options = {
|
||||
debug: true,
|
||||
var browserifyOpt = {
|
||||
entries: [].concat(entryFiles),
|
||||
debug: (options && 'sourcemaps' in options) ? options.sourcemaps : true,
|
||||
detectGlobals: false, // dont insert `process`, `global`, `__filename`, and `__dirname`
|
||||
bundleExternal: false, // dont bundle external modules
|
||||
//standalone: 'engine-framework',
|
||||
@@ -140,9 +144,25 @@ exports.createBundler = function createBundler(entryFiles, babelifyOpt) {
|
||||
console.error('Please run "npm install babelify".');
|
||||
throw e;
|
||||
}
|
||||
return new Browserify(entryFiles, options)
|
||||
|
||||
var b;
|
||||
if (options && options.cacheDir) {
|
||||
// https://github.com/royriojas/persistify
|
||||
const Persistify = require('persistify');
|
||||
b = Persistify(browserifyOpt, {
|
||||
recreate: false,
|
||||
cacheId: require('../../package.json').version + entryFiles,
|
||||
cacheDir: options.cacheDir
|
||||
});
|
||||
}
|
||||
else {
|
||||
const Browserify = require('browserify');
|
||||
b = new Browserify(browserifyOpt);
|
||||
}
|
||||
|
||||
return b
|
||||
.exclude(Path.join(__dirname, '../../package.json'))
|
||||
.transform(Babelify, babelifyOpt || {
|
||||
.transform(Babelify, (options && options.babelifyOpt) || {
|
||||
// presets: presets,
|
||||
plugins: plugins,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user