How to use the @babel/plugin-transform-modules-commonjs function in @babel/plugin-transform-modules-commonjs

To help you get started, we’ve selected a few @babel/plugin-transform-modules-commonjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zeit / next.js / packages / next / build / babel / plugins / commonjs.ts View on Github external
export default function NextToNextServer(...args: any): PluginObj {
  const commonjs = commonjsPlugin(...args)
  return {
    visitor: {
      Program: {
        exit(path: NodePath, state) {
          let foundModuleExports = false
          path.traverse({
            MemberExpression(path: any) {
              if (path.node.object.name !== 'module') return
              if (path.node.property.name !== 'exports') return
              foundModuleExports = true
            },
          })

          if (!foundModuleExports) {
            return
          }

@babel/plugin-transform-modules-commonjs

This plugin transforms ES2015 modules to CommonJS

MIT
Latest version published 18 days ago

Package Health Score

95 / 100
Full package analysis

Popular @babel/plugin-transform-modules-commonjs functions