diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-03-22 11:48:45 +0100 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-03-22 12:37:52 +0100 |
commit | df91a4ec347ba6e27184c6ea1117c226560fd3d0 (patch) | |
tree | 626d6ea2b5ac39c6d40f93da87600874d73ce5c0 /server/sonar-web/scripts | |
parent | 8da037d336f42543ef35d146be0adebea8928a6e (diff) | |
download | sonarqube-df91a4ec347ba6e27184c6ea1117c226560fd3d0.tar.gz sonarqube-df91a4ec347ba6e27184c6ea1117c226560fd3d0.zip |
migrate to webpack 4 (#39)
Diffstat (limited to 'server/sonar-web/scripts')
-rw-r--r-- | server/sonar-web/scripts/build.js | 53 | ||||
-rw-r--r-- | server/sonar-web/scripts/utils/formatSize.js | 2 |
2 files changed, 14 insertions, 41 deletions
diff --git a/server/sonar-web/scripts/build.js b/server/sonar-web/scripts/build.js index c3469f538c3..92f8a426a29 100644 --- a/server/sonar-web/scripts/build.js +++ b/server/sonar-web/scripts/build.js @@ -21,34 +21,15 @@ process.env.NODE_ENV = 'production'; const chalk = require('chalk'); -const fs = require('fs-extra'); -const rimrafSync = require('rimraf').sync; const webpack = require('webpack'); -const paths = require('../config/paths'); +const sortBy = require('lodash/sortBy'); const formatSize = require('./utils/formatSize'); const getConfig = require('../config/webpack.config'); -const fast = process.argv.some(arg => arg.indexOf('--fast') > -1); - -const config = getConfig({ fast, production: true }); - -function clean() { - // Remove all content but keep the directory so that - // if you're in it, you don't end up in Trash - console.log(chalk.cyan.bold('Cleaning output directories and files...')); - - console.log(paths.appBuild + '/*'); - rimrafSync(paths.appBuild + '/*'); - - console.log(); -} +const config = getConfig({ production: true }); function build() { - if (fast) { - console.log(chalk.magenta.bold('Running fast build...')); - } else { - console.log(chalk.cyan.bold('Creating optimized production build...')); - } + console.log(chalk.cyan.bold('Creating optimized production build...')); console.log(); webpack(config, (err, stats) => { @@ -65,16 +46,17 @@ function build() { } const jsonStats = stats.toJson(); + const withoutSourceMaps = jsonStats.assets.filter(asset => !asset.name.endsWith('.map')); - console.log('Assets:'); - const assets = jsonStats.assets.slice(); - assets.sort((a, b) => b.size - a.size); - assets.forEach(asset => { - let sizeLabel = formatSize(asset.size); - const leftPadding = ' '.repeat(Math.max(0, 8 - sizeLabel.length)); - sizeLabel = leftPadding + sizeLabel; - console.log('', chalk.yellow(sizeLabel), asset.name); - }); + console.log(`Biggest assets (${withoutSourceMaps.length} total):`); + sortBy(withoutSourceMaps, asset => -asset.size) + .slice(0, 5) + .forEach(asset => { + let sizeLabel = formatSize(asset.size); + const leftPadding = ' '.repeat(Math.max(0, 8 - sizeLabel.length)); + sizeLabel = leftPadding + sizeLabel; + console.log('', chalk.yellow(sizeLabel), asset.name); + }); console.log(); const seconds = jsonStats.time / 1000; @@ -85,13 +67,4 @@ function build() { }); } -function copyPublicFolder() { - fs.copySync(paths.appPublic, paths.appBuild, { - dereference: true, - filter: file => file !== paths.appHtml - }); -} - -clean(); build(); -copyPublicFolder(); diff --git a/server/sonar-web/scripts/utils/formatSize.js b/server/sonar-web/scripts/utils/formatSize.js index e06ba0e183f..40aab4ab236 100644 --- a/server/sonar-web/scripts/utils/formatSize.js +++ b/server/sonar-web/scripts/utils/formatSize.js @@ -24,5 +24,5 @@ module.exports = function(bytes) { const k = 1000; // or 1024 for binary const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); - return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i]; + return parseFloat((bytes / Math.pow(k, i)).toFixed(0)) + ' ' + sizes[i]; }; |