You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2016 SonarSource SA
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. process.env.NODE_ENV = 'production';
  21. var chalk = require('chalk');
  22. var fs = require('fs');
  23. var path = require('path');
  24. var rimrafSync = require('rimraf').sync;
  25. var webpack = require('webpack');
  26. var paths = require('../config/paths');
  27. var formatSize = require('./utils/formatSize');
  28. var isFastBuild = process.argv.some(arg => arg.indexOf('--fast') > -1);
  29. var config = isFastBuild ?
  30. require('../config/webpack/webpack.config.fast') :
  31. require('../config/webpack/webpack.config.prod');
  32. // Remove all content but keep the directory so that
  33. // if you're in it, you don't end up in Trash
  34. console.log(chalk.cyan.bold('Cleaning output directories...'));
  35. console.log(paths.jsBuild + '/*');
  36. rimrafSync(paths.jsBuild + '/*');
  37. console.log(paths.cssBuild + '/*');
  38. rimrafSync(paths.cssBuild + '/*');
  39. console.log();
  40. if (isFastBuild) {
  41. console.log(chalk.magenta.bold('Running fast build...'));
  42. } else {
  43. console.log(chalk.cyan.bold('Creating optimized production build...'));
  44. }
  45. console.log();
  46. webpack(config, (err, stats) => {
  47. if (err) {
  48. console.log(chalk.red.bold('Failed to create a production build!'));
  49. console.log(chalk.red(err.message || err));
  50. process.exit(1);
  51. }
  52. if (stats.compilation.errors && stats.compilation.errors.length) {
  53. console.log(chalk.red.bold('Failed to create a production build!'));
  54. stats.compilation.errors.forEach(err => console.log(chalk.red(err.message || err)));
  55. process.exit(1);
  56. }
  57. var jsonStats = stats.toJson();
  58. console.log('Assets:');
  59. var assets = jsonStats.assets.slice();
  60. assets.sort((a, b) => b.size - a.size);
  61. assets.forEach(asset => {
  62. var sizeLabel = formatSize(asset.size);
  63. var leftPadding = ' '.repeat(8 - sizeLabel.length);
  64. sizeLabel = leftPadding + sizeLabel;
  65. console.log('', chalk.yellow(sizeLabel), asset.name);
  66. });
  67. console.log();
  68. var seconds = jsonStats.time / 1000;
  69. console.log('Duration: ' + seconds.toFixed(2) + 's');
  70. console.log();
  71. console.log(chalk.green.bold('Compiled successfully!'));
  72. });