compile.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. const fs = require('fs-extra');
  2. const debug = require('debug')('app:bin:compile');
  3. const webpackCompiler = require('../build/webpack-compiler');
  4. const webpackConfig = require('../build/webpack.config');
  5. const config = require('../config');
  6. const paths = config.utils_paths;
  7. const compile = () => {
  8. debug('Starting compiler.');
  9. return Promise.resolve()
  10. .then(() => webpackCompiler(webpackConfig))
  11. .then(stats => {
  12. if (stats.warnings.length && config.compiler_fail_on_warning) {
  13. throw new Error('Config set to fail on warning, exiting with status code "1".');
  14. }
  15. debug('Copying static assets to dist folder.');
  16. fs.copySync(paths.client('static'), paths.dist());
  17. fs.copySync(paths.client('assets'), paths.dist('assets'));
  18. fs.copySync(paths.project('static'), paths.dist());
  19. fs.copySync(paths.project('assets'), paths.dist('assets'));
  20. fs.copySync(paths.lib(), paths.dist());
  21. })
  22. .then(() => {
  23. debug('Compilation completed successfully.');
  24. })
  25. .catch(err => {
  26. debug('Compiler encountered an error.', err);
  27. process.exit(1);
  28. });
  29. };
  30. compile();