util.js

  1. /* @flow */
  2. /* eslint-disable no-process-env */
  3. /**
  4. * Generic utilities and configuration objects.
  5. *
  6. * @module util
  7. */
  8. /**
  9. * `true` on Node.js
  10. *
  11. * @memberof module:util
  12. * @constant {boolean} isNode
  13. * @example
  14. * import {isNode} from 'webcompiler';
  15. * // or - import {isNode} from 'webcompiler/lib/util';
  16. * // or - var isNode = require('webcompiler').isNode;
  17. * // or - var isNode = require('webcompiler/lib/util').isNode;
  18. */
  19. export const isNode = 'undefined' !== typeof process && process.release && 'node' === process.release.name;
  20. /**
  21. * `true` if the `NODE_ENV` environment variable is set to `"production"`
  22. *
  23. * @memberof module:util
  24. * @constant {boolean} isProduction
  25. * @example
  26. * import {isProduction} from 'webcompiler';
  27. * // or - import {isProduction} from 'webcompiler/lib/util';
  28. * // or - var isProduction = require('webcompiler').isProduction;
  29. * // or - var isProduction = require('webcompiler/lib/util').isProduction;
  30. */
  31. export const isProduction = 'production' === process.env.NODE_ENV;
  32. /**
  33. * Babel configuration for the Node.js.
  34. *
  35. * @memberof module:util
  36. * @member {Object} babelBEOptions
  37. * @example
  38. * import {babelBEOptions} from 'webcompiler';
  39. * // or - import {babelBEOptions} from 'webcompiler/lib/util';
  40. * // or - var babelBEOptions = require('webcompiler').babelBEOptions;
  41. * // or - var babelBEOptions = require('webcompiler/lib/util').babelBEOptions;
  42. */
  43. export const babelBEOptions = {
  44. babelrc: false,
  45. presets: ['es2016', 'es2017', 'stage-2', 'react'],
  46. plugins: [
  47. ['transform-es2015-modules-commonjs', {loose: true}]
  48. ]
  49. };
  50. /**
  51. * Babel configuration for the browser.
  52. *
  53. * @memberof module:util
  54. * @member {Object} babelFEOptions
  55. * @example
  56. * import {babelFEOptions} from 'webcompiler';
  57. * // or - import {babelFEOptions} from 'webcompiler/lib/util';
  58. * // or - var babelFEOptions = require('webcompiler').babelFEOptions;
  59. * // or - var babelFEOptions = require('webcompiler/lib/util').babelFEOptions;
  60. */
  61. export const babelFEOptions = {
  62. cacheDirectory: true,
  63. babelrc: false,
  64. presets: [
  65. ['es2015', {
  66. // temporarily disabled until `webpack` 2.3 and `webpack-hot-loader` 3.0 are available
  67. // modules: false,
  68. loose: true
  69. }],
  70. 'es2016', 'es2017', 'stage-2', 'react'
  71. ],
  72. plugins: ['transform-runtime']
  73. };