在 Rollup 中,如何让 --external 在直接指向要排除的模块的命令行上工作? (没有节点解析插件)

In Rollup How do I get --external to work on the command line directly pointing to the module to exclude? (no node resolve plugin)

文档讨论了在节点解析插件的上下文中使用 external,但我没有使用它。我想排除 lit-html (这是原生 es6 模块),以便这些导入保留在包中。

在我的模块中,我使用 import { html, render } from '../../node_modules/lit-html/lit-html.js' 导入它们;它在浏览器中运行良好。

我已经尝试了所有路径排列,包括像 rollup --format=esm --file=dist/bundle.js -- src/main.js --external 'node_modules/lit-html/lit-html.js' 这样的相对路径,只得到 [!] Error: Could not resolve entry (--external).

它甚至不说是否找到了文件,更不用说是什么问题了。

您的命令似乎有误,请使用 -i 指示输入文件或尝试将 -- src/main.js 移至命令末尾(不带破折号)。

关于外部部分,如果不使用导入的确切 ID,不要认为它会起作用,但值得一试。

使用配置文件:

module.exports = {
      input: 'src/main.js',
      external:[
        '../../node_modules/lit-html/lit-html.js'
      ],
      output: {
      format: 'esm',
      file: './dist/bundle.js',
      sourcemap: true
    }
  }