compile.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. if (fs.existsSync(paths.client('static')))
  17. fs.copySync(paths.client('static'), paths.dist());
  18. if (fs.existsSync(paths.client('assets')))
  19. fs.copySync(paths.client('assets'), paths.dist('assets'));
  20. if (fs.existsSync(paths.project('static')))
  21. fs.copySync(paths.project('static'), paths.dist());
  22. if (fs.existsSync(paths.project('assets')))
  23. fs.copySync(paths.project('assets'), paths.dist('assets'));
  24. if (fs.existsSync(paths.lib()))
  25. fs.copySync(paths.lib(), paths.dist());
  26. })
  27. .then(() => {
  28. debug('Compilation completed successfully.');
  29. })
  30. .catch(err => {
  31. debug('Compiler encountered an error.', err);
  32. process.exit(1);
  33. });
  34. };
  35. compile();