【发布时间】:2019-09-24 14:53:02
【问题描述】:
好的,我是第一次使用汇总工具,我喜欢它使代码变得多么小。摇树很棒。但是,我在让它正确包含所有内容时遇到了一些麻烦。我尝试使用单个入口点 exp.js,从各种文件中导出内容,如下所示:
export {
dashboardCharts
} from './dashboard.js';
我的 rollup.config.js 看起来像
export default {
// tell rollup our main entry point
input: [
'assets/js/exp.js',
],
output: {
name: 'helloworld',
file: 'build/js/main.js',
format: 'iife'
// format: 'umd'
},
plugins: [
resolve({
// pass custom options to the resolve plugin
customResolveOptions: {
moduleDirectory: 'node_modules'
}
}),
multiEntry()
// terser(),
],
};
dashboard.js 文件包含 datatables 库,因此 datatables 包含在包 main.js 中。但是,datatables通过测试来测试是否应该走commonjs路径
else if ( typeof exports === 'object' ) {
// CommonJS
module.exports = function (root, $) {
我正在尝试在浏览器中执行此操作,所以我不想要 commonjs 路径。 Rollup 的顶级作用域声明为
var helloworld = (function (exports) {
所以 export 最终是一个空对象,浏览器尝试执行 commonjs 路径,我们得到一个“模块未定义”错误。
我觉得我真的很接近,但我在这里缺少一个简单的解决方案。我也尝试过使用 umd 格式而不是 iife,但没有帮助。我应该使用不同版本的数据表吗?
【问题讨论】:
-
你看过commonjs rollup 插件了吗?数据表也可能会将其短路,但值得一试:github.com/rollup/rollup-plugin-commonjs
标签: javascript jquery datatables rollupjs