Skip to content

Commit

Permalink
Support .mjs extension
Browse files Browse the repository at this point in the history
  • Loading branch information
chadhietala committed Sep 3, 2019
1 parent de1ef5d commit b521e6b
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ UglifyWriter.prototype.build = function() {

mkdirp.sync(path.dirname(outFile));

if (relativePath.slice(-3) === '.js' && !writer.excludes.match(relativePath)) {
if (this._isJSExt(relativePath) && !writer.excludes.match(relativePath)) {
// wrap this in a function so it doesn't actually run yet, and can be throttled
let uglifyOperation = function() {
return writer.processFile(inFile, outFile, relativePath, writer.outputPath);
Expand All @@ -90,7 +90,7 @@ UglifyWriter.prototype.build = function() {
}
return uglifyOperation();
} else if (relativePath.slice(-4) === '.map') {
if (writer.excludes.match(`${relativePath.slice(0, -4)}.js`)) {
if (writer.excludes.match(`${relativePath.slice(0, -4)}.{js,mjs}`)) {
// ensure .map files for excluded JS paths are also copied forward
symlinkOrCopy.sync(inFile, outFile);
}
Expand All @@ -114,6 +114,10 @@ UglifyWriter.prototype.build = function() {
});
};

UglifyWriter.prototype._isJSExt = function(relativePath) {
return relativePath.slice(-3) === '.js' || relativePath.slice(-4) === '.mjs';
};

UglifyWriter.prototype.processFile = function(inFile, outFile, relativePath, outDir) {
// don't run this in the workerpool if concurrency is disabled (can set JOBS <= 1)
if (this.async && this.concurrency > 1) {
Expand Down
Loading

0 comments on commit b521e6b

Please sign in to comment.