Skip to content

Commit

Permalink
chore: update rollup and uglify and the build process (#5096)
Browse files Browse the repository at this point in the history
This is upgrades rollup and uglify to latest versions. It also rewrites the rollup config to take advantage of the newest features of rollup. Minification is also split up into a separate process, mostly to speed up the build. The total build type can go down from about 2.5 minutes to around 1 minute for all the generated javascript files.
  • Loading branch information
gkatsev committed Apr 19, 2018
1 parent b10b9f9 commit 97db94e
Show file tree
Hide file tree
Showing 6 changed files with 439 additions and 484 deletions.
29 changes: 1 addition & 28 deletions build/grunt.js
Expand Up @@ -82,29 +82,6 @@ module.exports = function(grunt) {
build: ['build/temp/*', 'es5'],
dist: ['dist/*']
},
uglify: {
options: {
preserveComments: 'some',
screwIE8: false,
mangle: true,
compress: {
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true,
drop_console: true
}
},
build: {
files: {
'build/temp/alt/video.novtt.min.js': 'build/temp/alt/video.novtt.js',
'build/temp/video.min.js': 'build/temp/video.js'
}
}
},
dist: {},
watch: {
dist: {
Expand All @@ -116,10 +93,6 @@ module.exports = function(grunt) {
],
tasks: ['copy:dist']
},
minify: {
files: ['build/temp/video.js'],
tasks: ['uglify']
},
skin: {
files: ['src/css/**/*'],
tasks: ['skin']
Expand Down Expand Up @@ -362,7 +335,7 @@ module.exports = function(grunt) {
}
},
rollupall: {
command: 'npm run rollup -- --no-progress && npm run rollup-minify -- --no-progress',
command: 'npm run rollup -- --no-progress && npm run minify',
options: {
preferLocal: true
}
Expand Down
46 changes: 46 additions & 0 deletions build/minify.js
@@ -0,0 +1,46 @@
import fs from 'fs';
import uglify from 'uglify-js';
import maxmin from 'maxmin';

const options = {
nameCache: {},
output: {
comments: 'some'
},
mangle: true,
compress: {
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true,
drop_console: true,
typeofs: false
}
};

const minify = (file, dest) => {
const code = fs.readFileSync(file, 'utf8');
const minified = uglify.minify(code, options);

if (minified.error) {
console.error(minified.error);
return;
}

if (minified.warnings) {
console.warn(minified.warnings);
}

fs.writeFileSync(dest, minified.code, 'utf8');
console.log('File', dest, 'created:', maxmin(code, minified.code, true));
};

console.log('Minifying files\n');

minify('dist/video.js', 'dist/video.min.js');
minify('dist/alt/video.novtt.js', 'dist/alt/video.novtt.min.js');
minify('dist/alt/video.core.js', 'dist/alt/video.core.min.js');
minify('dist/alt/video.core.novtt.js', 'dist/alt/video.core.novtt.min.js');

0 comments on commit 97db94e

Please sign in to comment.