@zohodesk/client_build_tool
Version:
A CLI tool to build web applications and client libraries
46 lines (37 loc) • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getBabelPlugin = getBabelPlugin;
var _modeUtils = require("../bundler/webpack/common/modeUtils");
var _addDefaultPlugins = require("./addDefaultPlugins");
const babelPluginMapping = {
removeAttribute: './babel_plugins/removeAttributesPlugin',
removePropTypes: 'babel-plugin-transform-react-remove-prop-types',
devConsoleExclude: 'babel-plugin-transform-remove-console'
};
const babelPluginOrder = ['removeAttribute', 'removePropTypes', 'devConsoleExclude'];
function getBabelPlugin(options, command) {
const {
mode
} = options;
const {
alias
} = options.resolve;
let customPlugins = [];
if (command == 'es' || command == 'lib') {
customPlugins = [[require.resolve('babel-plugin-module-resolver'), {
root: ['./'],
alias
}]];
}
const {
babelCustomizations
} = options;
if ((0, _modeUtils.isProductionMode)(mode)) {
const configCreator = _addDefaultPlugins.addDefaultPlugins;
const plugins = babelPluginOrder.map(p => configCreator(babelCustomizations[p], babelPluginMapping[p]));
customPlugins = plugins;
}
return customPlugins.filter(Boolean);
}