Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function makeWebpackConfig({ entry, externals }) {
const externalsRegex = makeExternalsRegex(externals.externalPackages)
const isExternalRequest = (request) => {
const isPeerDep = externals.externalPackages.length ? externalsRegex.test(request) : false
const isBuiltIn = externals.externalBuiltIns.includes(request)
return isPeerDep || isBuiltIn
}
debug('external packages %o', externalsRegex)
const builtInNode = {}
builtinModules.forEach(mod => {
builtInNode[mod] = 'empty'
})
builtInNode['setImmediate'] = false
builtInNode['console'] = false
builtInNode['process'] = false
builtInNode['Buffer'] = false
return {
entry: entry,
mode: 'production',
// bail: true,
optimization: {
namedChunks: true,
runtimeChunk: { name: 'runtime' },
splitChunks: {
export const addBuiltinsToObject = (o: LooseObject): void =>
builtinModules.forEach(m =>
Object.defineProperty(o, m, {
configurable: true,
// Keeping it non-enumerable so as to not pollute the output from
// running `global` in the repl, which would in turn actually
// trigger the getter, rendering this whole mechanism useless.
enumerable: false,
get() {
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const required = require(m)
delete o[m]
Object.defineProperty(o, m, {
configurable: true,
enumerable: false,
writable: true,
value: required