【问题标题】:How to import and bundle lodash using rollup?如何使用汇总导入和捆绑 lodash?
【发布时间】:2020-09-15 13:32:58
【问题描述】:

我无法通过汇总导入 lodash。我尝试了一些不同的配置,但没有找到任何可行的配置。

使用 lodash

import compose from "lodash/fp/compose";
compose(removeDocumentInformation)(document.saveXML());

汇总配置

  {
    input: "src/renderer/renderer.tsx",
    output: [{ dir: "app/build", format: "es", sourcemap: true }],
    plugins: [
      typescript(),
      replace({
        "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
        // Gets rid of console warning to install React Dev Tools for a better development experience
        __REACT_DEVTOOLS_GLOBAL_HOOK__: "({ isDisabled: true })",
      }),
      commonjs({
        namedExports: {
          "node_modules/react/index.js": [
            "useEffect",
            "useState",
            "Component",
            "PureComponent",
            "PropTypes",
            "createElement",
            "cloneElement",
            "Children",
          ],
          "node_modules/react-dom/index.js": ["render"],
          "node_modules/lodash/fp/compose.js": [],
        },
      }),
      resolve({
        mainFields: ["module", "main", "jsnext:main", "browser"],
        extensions: [".js", ".jsx", ".ts", ".tsx"],
      }),
      copy({
        targets: [
          {
            src: ["src/renderer/index.html", "src/renderer/styles.css"],
            dest: "app/build",
          },
        ],
      }),
    ],
  },

错误似乎与问题无关,但如果我删除 lodash 就会消失

src/renderer/renderer.tsx → app/build...
(!) Unresolved dependencies
crypto...
url...
path...
http...
https...
net...
tls...
querystring...
stream...
events...
asserts...
zlib...
fs...
buffer...

[!] Error: Unexpected token (Note that you need @rollup/plugin-json to import JSON files)
node_modules\mime-db\db.json (2:40)

【问题讨论】:

    标签: lodash rollup


    【解决方案1】:

    不确定它是否已解决,因为它已被要求超过一年。 该项目似乎比“lodash”更复杂,它有反应并使用打字稿。最好在 github 上提供整个项目环境。 或者你可以试试@rollup/plugin-json

    【讨论】:

      猜你喜欢
      • 2021-10-25
      • 2017-03-23
      • 2021-04-13
      • 2018-12-03
      • 1970-01-01
      • 2020-01-21
      • 2018-03-16
      • 1970-01-01
      • 2020-08-10
      相关资源
      最近更新 更多