Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
perf(compiler/js): browserify only necessary files
Browse files Browse the repository at this point in the history
  • Loading branch information
zanona committed Nov 19, 2017
1 parent 0c0429f commit ca52b2a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions min/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ module.exports = function (files) {
}
function brwsrfy(file) {
return new Promise((resolve, reject) => {
const importMatch = /^(?:\s*)?import\b|\brequire\(/gm;
if (!file.contents.match(importMatch)) { return resolve(file); }
var s = new require('stream').Readable(),
path = require('path').parse(process.cwd() + '/' + file.name);
s.push(file.contents);
Expand Down Expand Up @@ -127,11 +125,15 @@ module.exports = function (files) {
}

if (file.name.match(/\.js$/)) {
return regenerate(file)
.then(brwsrfy)
.then(babelify)
.then(uglify)
.catch(formatError);
if (file.contents.match(/module.exports/)) return file;
let transpile;
if (file.hasImports) {
transpile = brwsrfy(file);
} else {
transpile = regenerate(file).then(babelify);
}
return transpile.then(uglify).catch(formatError);

} else if (file.name.match(/\.(json|ld\+json)$/)) {
return minifyJSON(file, formatError);
} else {
Expand Down

0 comments on commit ca52b2a

Please sign in to comment.