在node_modules的'myPackage'中有一个js文件'hello.js'
这是我的hello.js
console.log('hello');
在我的项目中,我想使用import hello.js
如果我的main.js是
//some syntax that import hello.js
console.log('hello2');
我的目标是
hello
hello2
我怎样才能做到这一点?
require()将不带“ ./”或“ /”前缀的路径解析为node_modules:
//some syntax that import hello.js
let exportOfHelloJSIfYouWishToCatchIt = require("myPackage/hello");
console.log('hello2');
应该工作得很好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句