汇总中的自定义命名导出不起作用
Custom Named Exports in Rollup Not Working
我是第一次使用 Rollup(按照 angular.io 中的示例),但出现此错误:
'AuthHttp' 未由 'node_modules/angular2-jwt/angular2-jwt.js'
导出
来自 app.module.js 中的这一行:
13: 从 'angular2-jwt/angular2-jwt' 导入 { AuthHttp, AuthConfig };
文档说您可以通过在 rollup-config.js 文件中指定自定义命名导出来更正此问题,如下所示:
commonjs({
namedExports: {
// left-hand side can be an absolute path, a path
// relative to the current directory, or the name
// of a module in node_modules
'node_modules/my-lib/index.js': [ 'named' ]
}
})
这是我汇总的相关部分-config.js 文件:
plugins: [
nodeResolve({jsnext: true, module: true}),
commonjs({
include: 'node_modules/rxjs/**',
namedExports: {
'node_modules/angular2-jwt/angular2-jwt.js': [ 'AuthHttp' ]
}
}),
但是这没有任何效果,错误仍然存在。关于如何纠正这个问题有什么建议吗?
试试这个,让我知道你的进展情况:
汇总-config.js
commonjs({ include: ['node_modules/rxjs/**',
'node_modules/angular2-jwt/angular2-jwt.js'],
..
})
你也npm i -D rollup-plugin-node-resolve
了吗?
jsnext 显示在 rollup-plugin-node-resolve 文档中
here.
在 issues.
中也有关于在下一版本中删除它的神秘评论
然而 rollup wiki docs 相对于 jsnext 似乎也很奇怪。
他们只是说它被 pkg.module 取代了,这对我来说并不能真正澄清事情。所以也许 删除标志或切换到 false?
有一个汇总 starter-project 配置文件。它在目标数组中引用 pkg.module。
还有一个 rollup-starter-lib 配置示例。
这是汇总 guide
更新:
命名导出似乎是 rollup-plugin-commonjs 的一部分
npm i -D rollup-plugin-commonjs
Typically, you would use this plugin alongside
rollup-plugin-node-resolve, so that you could bundle your CommonJS
dependencies in node_modules.
`// explicitly specify unresolvable named exports
// (see below for more details)
namedExports: { './module.js': ['foo', 'bar' ] }, // Default: undefined`
根据 here,您是否也正确设置了 tsconfig-aot.json?
我是第一次使用 Rollup(按照 angular.io 中的示例),但出现此错误:
'AuthHttp' 未由 'node_modules/angular2-jwt/angular2-jwt.js'
导出来自 app.module.js 中的这一行:
13: 从 'angular2-jwt/angular2-jwt' 导入 { AuthHttp, AuthConfig };
文档说您可以通过在 rollup-config.js 文件中指定自定义命名导出来更正此问题,如下所示:
commonjs({
namedExports: {
// left-hand side can be an absolute path, a path
// relative to the current directory, or the name
// of a module in node_modules
'node_modules/my-lib/index.js': [ 'named' ]
}
})
这是我汇总的相关部分-config.js 文件:
plugins: [
nodeResolve({jsnext: true, module: true}),
commonjs({
include: 'node_modules/rxjs/**',
namedExports: {
'node_modules/angular2-jwt/angular2-jwt.js': [ 'AuthHttp' ]
}
}),
但是这没有任何效果,错误仍然存在。关于如何纠正这个问题有什么建议吗?
试试这个,让我知道你的进展情况:
汇总-config.js
commonjs({ include: ['node_modules/rxjs/**',
'node_modules/angular2-jwt/angular2-jwt.js'],
..
})
你也npm i -D rollup-plugin-node-resolve
了吗?
jsnext 显示在 rollup-plugin-node-resolve 文档中 here.
在 issues.
中也有关于在下一版本中删除它的神秘评论然而 rollup wiki docs 相对于 jsnext 似乎也很奇怪。 他们只是说它被 pkg.module 取代了,这对我来说并不能真正澄清事情。所以也许 删除标志或切换到 false?
有一个汇总 starter-project 配置文件。它在目标数组中引用 pkg.module。
还有一个 rollup-starter-lib 配置示例。
这是汇总 guide
更新:
命名导出似乎是 rollup-plugin-commonjs 的一部分
npm i -D rollup-plugin-commonjs
Typically, you would use this plugin alongside rollup-plugin-node-resolve, so that you could bundle your CommonJS dependencies in node_modules.
`// explicitly specify unresolvable named exports
// (see below for more details)
namedExports: { './module.js': ['foo', 'bar' ] }, // Default: undefined`
根据 here,您是否也正确设置了 tsconfig-aot.json?