MCPcopy Index your code
hub / github.com/cookpete/react-player / build

Function build

scripts/builder/builder.js:24–105  ·  view source on GitHub ↗
(positionals, args)

Source from the content-addressed store, hash-verified

22}
23
24export async function build (positionals, args) {
25 // https://esbuild.github.io/api/#live-reload
26 const livereloadJs = 'new EventSource(\'/esbuild\').addEventListener(\'change\', () => location.reload());'
27
28 // Assigns external modules to global variables.
29 // https://github.com/evanw/esbuild/issues/337
30 const plugins = {
31 'global-externals': (arg) => {
32 const options = JSON.parse(arg)
33 const filter = new RegExp(`^${Object.keys(options)}$`)
34
35 return {
36 name: 'global-externals-plugin',
37 setup (build) {
38 build.onResolve({ filter }, (args) => ({
39 path: args.path,
40 namespace: 'global-externals-plugin'
41 }))
42 build.onLoad({ filter: /.*/, namespace: 'global-externals-plugin' }, (args) => {
43 const contents = `module.exports = ${options[args.path]}`
44 return { contents }
45 })
46 }
47 }
48 }
49 }
50
51 const options = {
52 logLevel: 'info',
53 entryPoints: positionals,
54 outfile: args.outfile,
55 outdir: args.outfile ? undefined : args.outdir ?? 'dist',
56 target: args.target ?? 'es2019',
57 bundle: args.bundle,
58 minify: args.minify,
59 format: args.format,
60 platform: args.platform,
61 sourcemap: args.sourcemap,
62 splitting: args.splitting,
63 globalName: args['global-name'],
64 external: argsArray(args, 'external'),
65 outExtension: argsObject(args, 'out-extension'),
66 banner: argsObject(args, 'banner'),
67 plugins: Object.entries(argsObject(args, 'plugin'))
68 .map(([name, options]) => plugins[name](options)),
69 define: {
70 'globalThis.__TEST__': 'false',
71 ...argsObject(args, 'define')
72 },
73 loader: {
74 '.js': 'jsx',
75 ...argsObject(args, 'loader')
76 },
77 footer: {
78 ...argsObject(args, 'footer'),
79 js: (args['footer:js'] ?? '') +
80 (args.livereload ? `\n${livereloadJs}` : '')
81 }

Callers 2

testFunction · 0.90
cliBuildFunction · 0.85

Calls 2

argsArrayFunction · 0.85
argsObjectFunction · 0.85

Tested by 1

testFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…