【问题标题】:Why does rollup.js not include - exclusively - exported values in its output?为什么 rollup.js 在其输出中不包括 - 专门 - 导出的值?
【发布时间】:2016-09-04 13:47:00
【问题描述】:

我是 Rollup 的新手 - rollupjs.org - 不明白为什么要删除导出的值;大概是在汇总期间通过 treeshaking 进行的。

我有一个data.json,其中包含一些我想作为模块的一部分提供的基本数据:

{
    "colors": ["red", "green", "blue"],
    "shapes": ["circle", "triangle", "square"]
}

...以及将导出它们的模块:

import { colors, shapes } from './data.json';

function run() {
  console.log('Run, Forest, Run.');
}

export default run;

export {
  colors,
  shapes
};

rollup.js 是否不将导出语句识别为“使用”,因此仅在其中的任何内容都会从输出中得到“treeshaken”?

【问题讨论】:

  • 请向我们展示您是如何导入该模块的,如何在应用程序上调用 Rollup,以及结果如何。

标签: javascript json ecmascript-6 rollupjs es6-modules


【解决方案1】:

如果 entry 模块 导出 colorsshapes,则视为“使用”这些值。如果某些内部模块导出它们,则只有在另一个模块导入 colorsshapes 并使用它们时才会包含它们。

这里是demonstration of the first case(入口模块导出值),这里是demonstration of the second case(值由not-main.js导出)。

如果您的情况不是这样,您可能遇到了错误,在这种情况下请file an issue

【讨论】:

  • 感谢您的回复。你是对的,rollup.js 正在执行它应该的;我认为我迷失在我的抽象层 - 太多的间接 - 看到我正在导出正确的“事物”但在错误的级别。一旦我将导出移动到正确的位置,现在一切正常。
猜你喜欢
  • 2021-12-10
  • 2016-09-04
  • 2021-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-21
  • 1970-01-01
  • 2016-10-13
相关资源
最近更新 更多