使用 Rollup 保留独立评论

Jus*_*elt 5 rollupjs

我试图用汇总保留尾随的独立评论。我简要地浏览了使用插件扩展 rollup 或深入研究 AST,但正在寻找可能的解决方案的指导。

输入

// Some comment

const foo = {};

// Another comment <-- I want this to remain

export { foo };
Run Code Online (Sandbox Code Playgroud)

输出

(function (exports) {
    'use strict';

    // Some comment

    const foo = {};

    exports.foo = foo;

    return exports;

}({}));
Run Code Online (Sandbox Code Playgroud)

汇总配置

export default [
  {
    input: "src/index.js",
    plugins: [],
    output: {
      file: "dist/index.js",
      format: "iife",
      name: "foo"
    },
    treeshake: false
  }
];
Run Code Online (Sandbox Code Playgroud)