Skip to content

Instantly share code, notes, and snippets.

@m-allanson
Created December 1, 2016 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-allanson/c1b3d031f3833bbf1a86f1ffcc0cc495 to your computer and use it in GitHub Desktop.
Save m-allanson/c1b3d031f3833bbf1a86f1ffcc0cc495 to your computer and use it in GitHub Desktop.
Regex find & replace to convert ES6 imports to CommonJS requires
// matches:
// import foo from "../foo"
(import )((\w)+)( from )"((.|\/)*\w)"
// replaces with:
// const foo = require("../foo")
const $2 = require("$5")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment