diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-12-18 15:51:21 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2018-12-20 11:41:49 +0100 |
commit | 9c3818394a97ff1b9d8e92f781bcd4a911ee9838 (patch) | |
tree | f41cc866a2fafd5b0dfba65cc668c723c64b41c9 /server/sonar-web/scripts/build.js | |
parent | 687c3b52b21afb9f7e8e80b4329921b1bfef1257 (diff) | |
download | sonarqube-9c3818394a97ff1b9d8e92f781bcd4a911ee9838.tar.gz sonarqube-9c3818394a97ff1b9d8e92f781bcd4a911ee9838.zip |
create a separate js bundle for legacy browsers (#1073)
Diffstat (limited to 'server/sonar-web/scripts/build.js')
-rw-r--r-- | server/sonar-web/scripts/build.js | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/server/sonar-web/scripts/build.js b/server/sonar-web/scripts/build.js index 1b1a952c430..47aaf51827b 100644 --- a/server/sonar-web/scripts/build.js +++ b/server/sonar-web/scripts/build.js @@ -24,44 +24,44 @@ const chalk = require('chalk'); const webpack = require('webpack'); const sortBy = require('lodash/sortBy'); const formatSize = require('./utils/formatSize'); -const getConfig = require('../config/webpack.config'); +const getConfigs = require('../config/webpack.config'); -const config = getConfig({ production: true }); +const configs = getConfigs({ production: true }); function build() { console.log(chalk.cyan.bold('Creating optimized production build...')); console.log(); - webpack(config, (err, stats) => { + webpack(configs, (err, stats) => { if (err) { console.log(chalk.red.bold('Failed to create a production build!')); console.log(chalk.red(err.message || err)); process.exit(1); } - if (stats.compilation.errors && stats.compilation.errors.length) { - console.log(chalk.red.bold('Failed to create a production build!')); - stats.compilation.errors.forEach(err => console.log(chalk.red(err.message || err))); - process.exit(1); - } - - const jsonStats = stats.toJson(); - const onlyJS = jsonStats.assets.filter(asset => asset.name.endsWith('.js')); - - console.log(`Biggest js chunks (${onlyJS.length} total):`); - sortBy(onlyJS, 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 report = (stats, bundleName, filesLimit = 10) => { + if (stats.compilation.errors && stats.compilation.errors.length) { + console.log(chalk.red.bold('Failed to create a production build!')); + stats.compilation.errors.forEach(err => console.log(chalk.red(err.message || err))); + process.exit(1); + } + const jsonStats = stats.toJson(); + const onlyJS = jsonStats.assets.filter(asset => asset.name.endsWith('.js')); + console.log(`Biggest js chunks (${onlyJS.length} total) [${bundleName}]:`); + sortBy(onlyJS, asset => -asset.size) + .slice(0, filesLimit) + .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; - console.log('Duration: ' + seconds.toFixed(2) + 's'); + report(stats.stats[0], 'modern'); console.log(); + report(stats.stats[1], 'legacy'); console.log(chalk.green.bold('Compiled successfully!')); }); |