Skip to content

Commit

Permalink
Make two separate minify functions for polyfills and detects
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinlondon authored and JakeChampion committed Feb 22, 2019
1 parent cf1d139 commit 9109e2a
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions tasks/node/buildsources.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Polyfill {

if (fs.existsSync(this.detectPath)) {
this.config.detectSource = fs.readFileSync(this.detectPath, 'utf8').replace(/\s*$/, '') || '';
this.config.detectSource = this.minify(this.config.detectSource).min;
this.config.detectSource = this.minifyDetect(this.config.detectSource).min;
validateSource(`if (${this.config.detectSource}) true;`, `${this.name} feature detect from ${this.detectPath}`);
}
});
Expand Down Expand Up @@ -189,7 +189,7 @@ class Polyfill {
error
};
})
.then(raw => this.minify(raw))
.then(raw => this.minifyPolyfill(raw))
.catch(error => {
throw {
message: `Error minifying ${this.name}`,
Expand All @@ -202,7 +202,30 @@ class Polyfill {
});
}

minify(source) {
minifyPolyfill(source) {
const raw = `\n// ${this.name}\n${source}`;

if (this.config.build && this.config.build.minify === false) {
// skipping any validation or minification process since
// the raw source is supposed to be production ready.
// Add a line break in case the final line is a comment
return { raw: raw + '\n', min: source + '\n' };
}
else {
validateSource(source, `${this.name} from ${this.sourcePath}`);

const minified = uglify.minify(source, {
fromString: true,
compress: { screw_ie8: false },
mangle: { screw_ie8: false },
output: { screw_ie8: false, beautify: false }
});

return { raw, min: minified.code };
}
}

minifyDetect(source) {
const raw = `\n// ${this.name}\n${source}`;

if (this.config.build && this.config.build.minify === false) {
Expand Down

0 comments on commit 9109e2a

Please sign in to comment.