How to use the buildExternalHelpers function from @babel/core

Find comprehensive JavaScript @babel/core.buildExternalHelpers code examples handpicked from public code repositorys.

193
194
195
196
197
198
199
200
201
202
  });
}


function buildCdnReact(dirname) {
  var s = babelCore.buildExternalHelpers(reactBabelHelpers, 'global');

  return makeTask('build-cdn-react: ' + dirname, function() {
    return browserifyStream(
      './build-targets/cdn-react.js',
fork icon446
star icon0
watch icon0

215
216
217
218
219
220
  });
}


function buildCdnAngular(dirname) {
  var s = babelCore.buildExternalHelpers(angularBabelHelpers, 'global');
fork icon446
star icon0
watch icon171

+ 15 other calls in file

71
72
73
74
75
76
77
78
79
}

function createHelperModule(helpers, format, minify) {
  const helpersWithDependencies = getHelpersWithDependencies(helpers);
  const addRegeneratorRuntime = helpersWithDependencies.includes('regeneratorRuntime');
  let helperSource = buildExternalHelpers(
    helpersWithDependencies.filter(h => h !== 'regeneratorRuntime'),
    'module',
  );
fork icon400
star icon1
watch icon2

+ 3 other calls in file

116
117
118
119
120
121
122
123
124
125
  'interopRequireWildcard',
];

minifyAndWriteJs(
  // @ts-ignore
  babelCore.buildExternalHelpers([...mainHelpers, ...amdHelpers]),
      'babel-helpers-full.min.js');

minifyAndWriteJs(
  // @ts-ignore
fork icon204
star icon1
watch icon2

+ 3 other calls in file

142
143
144
145
146
147
148
149
150
151
  'toArray',
  'toConsumableArray',
];

gulp.task('gen-babel-helpers', () => {
  const helpersCode = babelCore.buildExternalHelpers(babelHelperWhitelist);
  const minified =
      babelCore.transform(helpersCode, {presets: [babelPresetMinify]}).code;
  fs.mkdirpSync('./lib/');
  fs.writeFileSync('./lib/babel-helpers.min.js', minified, {encoding: 'utf-8'});
fork icon40
star icon0
watch icon0

9
10
11
12
13
14
15
16
17
18
  {},
  { simplifyComparisons: false }
);

minifyAndWriteJs(
  babelCore.buildExternalHelpers(helperWhitelist),
  'babel-helpers.min.js'
);

/**
fork icon21
star icon0
watch icon2

39
40
41
42
43
44
45
46
47
48
const HELPERS = '\0rollupPluginBabelHelpers.js';
return {
    name: 'import2require',
    options: () => {},
    resolveId: id => (id !== HELPERS ? null : id),
    load: id => (id !== HELPERS ? null : babel.buildExternalHelpers(null, 'module')),
    transform(code, filename) {
        if (filename === HELPERS) return null;
        // TODO: 优化匹配规则
        if (code.includes(` import(`)) {
fork icon20
star icon25
watch icon3

34
35
36
37
38
39
40
41
42
    if (id === BABEL_HELPERS) return id;
},

load(id) {
    if (id === BABEL_HELPERS) {
        return babelCore.buildExternalHelpers(null, 'module');
    }
    return;
},
fork icon2
star icon0
watch icon1