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.

22 lines
851 B

4 years ago
  1. 'use strict';
  2. var path = require('path'),
  3. fs = require('fs'),
  4. objectPath = require('object-path');
  5. var getContextDirectory = require('./get-context-directory');
  6. /**
  7. * Infer the compilation output directory from options.
  8. * Relative paths are resolved against the compilation context (or process.cwd() where not specified).
  9. * @this {{options: object}} A loader or compilation
  10. * @returns {undefined|string} The output path string, where defined
  11. */
  12. function getOutputDirectory() {
  13. /* jshint validthis:true */
  14. var base = objectPath.get(this, 'options.output.directory'),
  15. absBase = !!base && path.resolve(getContextDirectory.call(this), base),
  16. isValid = !!absBase && fs.existsSync(absBase) && fs.statSync(absBase).isDirectory();
  17. return isValid ? absBase : undefined;
  18. }
  19. module.exports = getOutputDirectory;