Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function build () {
const bundle = await rollup.rollup({
input,
external,
plugins: [multi()]
})
// const { output } = await bundle.generate(outputOptions)
await bundle.write(outputOptions)
// Override the sourcemapping to work w/ CJS
const content = /* `import NGN from './.browser/ngn-${pkg.version}.min.js'\n` + */fs.readFileSync(file)
.toString()
.replace("require('source-map-support/register.js');", '\n') // Not supported by browserify
.replace(/var NGN\s+=\s+_interop.*require.*\n?/i, '') // Remove NGN reference so it can be included from the appropriate build file at runtime.
.replace(/const\s+(.*)\s+?=\s+?JSON.parse\(fs.readFileSync\(.*endpoints/gi, 'const $1 = __ENDPOINTS__;') // This replacement is done to add the appropriate endpoints from package.json. Browserify cannot resolve the file at runtime, so it must be prebuilt (see prep script below).
// .replace(/(var NGN\s+=\s+_interop.*require\(['|"])(.*)(['|"].*\n?)/, `$1./.browser/ngn-${pkg.version}.min.js$3`)
// .replace('.node/index.js', `.browser/ngn-${pkg.version}.min.js`)
// .replace("require('source-map-support/register.js');", "var sourcemap = require('source-map-support');\nsourcemap.install();\n")