jne*_*orf 5 path relative-path node.js rollupjs
我想使用ebnfNPM 中的库并使用rollup. 由于ebnf已安装,node_modules我还使用了汇总插件rollup-plugin-node-resolve。
问题在于ebnf包含的代码require('..')- 在我的情况下 - 在我的情况下已解决dist。因此,它似乎..是相对于输出文件而不是相对于源文件进行解释的。
这是我的rollup.config.js(取自我的测试仓库 jneuendorf/rollup-broken-resolve):
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'cjs'
},
// name: 'MyModule',
plugins: [
resolve(),
commonjs(),
]
}
Run Code Online (Sandbox Code Playgroud)
这是一个问题rollup-plugin-node-resolve还是我做错了什么?
由于一些所需的外部库仍然只能作为 Common.js 模块使用,因此您也可以将它们转换为 ES 模块:
“由于 node_modules 文件夹中的大多数包可能是旧版 CommonJS 而不是 JavaScript 模块,因此您可能需要使用 rollup-plugin-commonjs”
https://github.com/rollup/rollup-plugin-commonjs
“将 CommonJS 模块转换为 ES6,以便它们可以包含在 Rollup 包中”