简体   繁体   English

在汇总中如何让 --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)

The documents talk about using external in the context of the node resolve plugin, but I am not using that.文档讨论在节点解析插件的上下文中使用external ,但我没有使用它。 I would like to exclude lit-html (which is native es6 modules) so that those imports remain in the bundle.我想排除 lit-html(这是原生 es6 模块),以便这些导入保留在包中。

In my module I import them with import { html, render } from '../../node_modules/lit-html/lit-html.js' ;在我的模块中,我使用 import { html, render } from '../../node_modules/lit-html/lit-html.js'导入它们; and it works great in the browser.它在浏览器中运行良好。

I have tried every permutation of path including relative path like rollup --format=esm --file=dist/bundle.js -- src/main.js --external 'node_modules/lit-html/lit-html.js' and just get [!] Error: Could not resolve entry (--external) .我已经尝试了所有路径排列,包括相对路径,如rollup --format=esm --file=dist/bundle.js -- src/main.js --external 'node_modules/lit-html/lit-html.js'和只是得到[!] Error: Could not resolve entry (--external)

It does not even say if the file is found, never mind what the problem is.它甚至不说是否找到了文件,不管问题是什么。

Seems your command is wrong, use -i to indicate the input file or try moving -- src/main.js to the end of the command without the dashes.似乎您的命令有误,请使用-i指示输入文件或尝试将-- src/main.js移动到命令末尾而不带破折号。

Regarding the external part, don't think it will work without using the exact id of the import but worth a try.关于外部部分,不要认为它会在不使用导入的确切 id 的情况下工作,但值得一试。

Using a config file:使用配置文件:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 指向分支时如何解决“找不到模块”? - How do I resolve “Cannot find module” when pointing to a branch? 如何使用 Rollup 动态获取静态文件(并与节点解析一起工作)? - How to get static files served dynamically with Rollup (and work along with node-resolve)? 如何从命令行(终端)使用节点访问模块 - How do I access a module using a node from the command line(terminal) 如何使用CommonJS插件使用汇总来部分包含Node.js模块 - How to partially include Node.js module using rollup with commonjs plugin 汇总:如何在文件开头添加一行? - rollup: How do I prepend a line to the beginning of my file? 使用节点如何将我的ES6-export-default模块导入我的命令行javascript程序? - Using node how do I import my ES6-export-default module into my command line javascript program? 如何处理多个字符串节点命令行参数? - How do I process multiple string node command line arguments? 我正在尝试运行 node.js,如何解决“找不到模块”错误? - I am trying to run node.js, how do I resolve "Cannot find module" error? 打字稿2无法解析外部节点模块 - Typescript 2 cannot resolve external node module 如何获得“ PowerTools”插件才能在MooTools上使用? - How do I get the 'PowerTools' plugin to work for MooTools?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM