我已经向 NPM 发布了一个简单的 js 库,我希望节点和浏览器都可以使用它,使用 rollup.js 我为 commonJs 和 ES 创建了 2 个单独的包
rollup.config.js
output: [
{
dir: "bin/common",
format: "cjs",
},
{
dir: "bin/esm",
format: "esm",
},
],
Run Code Online (Sandbox Code Playgroud)
cjs 捆绑包在节点中工作正常,但是我在使用 esm 捆绑包时遇到错误
索引.html
<html>
<head>
<script src="./src/index.js" type="module">
</script>
</head>
<body></body>
</html>
Run Code Online (Sandbox Code Playgroud)
索引.js
import * as myLib from "./node_modules/bin/esm/myLib.js";
console.log(myLib);
Run Code Online (Sandbox Code Playgroud)
由 rollup.js 生成的 MyLib.js ES 包
Object.defineProperty(exports, "__esModule", { // error is thrown from this line
value: true
});
exports["default"] = void 0;
/** Lib Related code (no external …
Run Code Online (Sandbox Code Playgroud)