vite-plugins
vite-plugins copied to clipboard
'require' in string will be unexpectedly parsed. eg. console.log("var foo = require('foo')")
Versions
- originjs: 1.0.2
- node: 14.18.1
Reproduction
source code:
console.error("You need to import react !\nExample: react=require('react')");
'vite-plugin-commonjs' output:
import * as __require_for_vite_iuMxJX from "react"
console.error("You need to import react !\nExample: react=__require_for_vite_iuMxJX");
It's a little difficult to identify require in a string by RegExp. I've considered using a AST, but this will slow down transform.
I have the same problem. Perhaps there could be an option to use an AST for those who need it? I'd rather have this plugin be slower than not work at all.