How to use the OptionManager function from babel-core

Find comprehensive JavaScript babel-core.OptionManager code examples handpicked from public code repositorys.

babel-core.OptionManager is a utility that handles and normalizes the configuration options passed to Babel.

97
98
99
100
101
102
103
104
105
106
107
108
109
110
}


function compile(filename) {
  var result = void 0;


  var opts = new _babelCore.OptionManager().init((0, _extend2.default)({ sourceRoot: _path2.default.dirname(filename) }, (0, _cloneDeep2.default)(transformOpts), { filename: filename }));


  var cacheKey = (0, _stringify2.default)(opts) + ":" + babel.version;


  var env = process.env.BABEL_ENV || process.env.NODE_ENV;
fork icon0
star icon0
watch icon1

+ 2 other calls in file

How does babel-core.OptionManager work?

babel-core.OptionManager is a class that handles the management of options and their defaults in Babel. It provides methods to parse, validate, and normalize options passed to Babel's core functions. The class also handles merging options from different sources and provides a convenient interface for plugins to access options.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
const babelCore = require("babel-core");

const optionsManager = new babelCore.OptionManager();

const defaultOptions = optionsManager.getDefaultOptions();
const userOptions = {
  /* user-provided options */
};

const options = optionsManager.init(
  Object.assign({}, defaultOptions, userOptions)
);

In this example, we create a new instance of the OptionManager, retrieve the default options, merge them with the user-provided options, and then validate and normalize the resulting options.