简体   繁体   English

React 和 react-dom 仍然被 rollup bundler 捆绑

[英]React and react-dom still being bundled from the rollup bundler

I'm not sure what I am doing wrong but I simply cannot build components with react hooks for rollup.js.我不确定我做错了什么,但我根本无法为 rollup.js 构建带有反应钩子的组件。 I have tries all the popular comments such as adding skip to my resolve addon and adding externals and adding as peerdependencies in package.json.我已经尝试了所有流行的评论,例如在我的解析插件中添加 skip 并添加外部组件并在 package.json 中添加为 peerdependencies。

My imports is as follows:我的进口如下:

 import resolve from "@rollup/plugin-node-resolve"; import commonjs from "@rollup/plugin-commonjs"; import typescript from "@rollup/plugin-typescript"; import { terser } from "rollup-plugin-terser"; import peerDepsExternal from "rollup-plugin-peer-deps-external"; import postcss from "rollup-plugin-postcss"; import image from "@rollup/plugin-image"; const packageJson = require("./package.json"); export default { input: "./src/index.ts", output: [ { file: packageJson.main, format: "cjs", sourcemap: true, }, { file: packageJson.module, format: "esm", sourcemap: true, }, ], external: ["react", "react-dom"], plugins: [ peerDepsExternal(), resolve({ skip: ["react", "react-dom"], }), commonjs(), typescript({ tsconfig: "./tsconfig.json", }), postcss({ plugins: [require("tailwindcss"), require("autoprefixer")], }), terser(), image(), ], };

For me 'rollup-plugin-ignore' worked.对我来说, 'rollup-plugin-ignore'起作用了。

  import ignore from 'rollup-plugin-ignore';
  ignore(['fs', 'net', 'react', 'react-dom', 'prop-types', 'PropTypes']),

And external like this和这样的外部

external: [
  (id) => /^react$|^react-dom$|^@babel\/runtime/.test(id),
];

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM