【问题标题】:How to use redux-form in peer dependency如何在对等依赖中使用 redux-form
【发布时间】:2018-03-12 05:32:48
【问题描述】:

我正在尝试使用汇总和 react-redud 创建登录表单的 ES6 模块。

我有以下配置的汇总:

const plugins = [
  // Unlike Webpack and Browserify, Rollup doesn't automatically shim Node
  // builtins like `process`. This ad-hoc plugin creates a 'virtual module'
  // which includes a shim containing just the parts the bundle needs.
  {
    resolveId(importee) {
      if (importee === processShim) return importee;
      return null;
    },
    load(id) {
      if (id === processShim) return 'export default { argv: [], env: {} }';
      return null;
    },
  },
  nodeResolve(),
  commonjs({
    include: 'node_modules/**',
    namedExports: {
      './node_modules/immutable/dist/immutable.js': ['fromJS', 'Map', 'List', 'Record', 'Iterable'],
      './node_modules/redux/dist/redux.js': ['createStore', 'combineReducers', 'bindActionCreators', 'applyMiddleware', 'compose'],
      './node_modules/react-redux/dist/react-redux.js': [' Provider', 'createProvider', 'connectAdvanced', 'connect'],
    },
  }),
  replace({
    'process.env.NODE_ENV': JSON.stringify(prod ? 'production' : 'development'),
  }),
  inject({
    process: processShim,
  }),
  json(),
  babel({
    plugins: ['external-helpers'],
    exclude: 'node_modules/**',
  }),
  cleanup(),
];

if (prod) plugins.push(uglify(), visualizer({ filename: './bundle-stats.html' }));

export default {
  input: 'src/index.js',
  sourcemap: true,
  name: pkg.name,
  external: ['react', 'react-dom', 'prop-types', 'styled-components', 'bootstrap-styled', 'classnames', 'react-transition-group', 'loaders', 'redux-form', 'redux', 'react-redux', 'react-intl', 'message-common', 'bootstrap-styled-motion'],
  exports: 'named',
  output,
  plugins,
  globals: { react: 'React', 'react-dom': 'ReactDom', 'prop-types': 'PropTypes', 'styled-components': 'styled', classnames: 'cn', 'react-transition-group': 'ReactTransitionGroup', loaders: 'loaders', 'redux-form': 'redux-form', 'react-intl': 'react-intl', 'message-common': 'message-common' },
};

我的汇总包很好,没有警告。

我已经尝试了所有导入的可能性:

import reduxForm from 'redux-form/lib/immutable/reduxForm';
import Field from 'redux-form/lib/immutable/Field';

import { Field, reduxForm } from 'redux-form/es/immutable';

import { Field, reduxForm } from 'redux-form/es/immutable';

但是没有任何效果,每次我在某个地方安装这个模块时,转译后的 ES 都会用这些导入替换这一行

import reactRedux from 'react-redux';
import redux from 'redux';

我认为这是因为 redux-form 依赖于这两个。因为这两个模块没有默认导出,所以会报错:

./node_modules/login-form/dist/login-form.es.js 中的警告 3471:19-24 “在‘redux’中找不到导出‘default’(导入为‘redux’)

./node_modules/login-form/dist/login-form.es.js 中的警告 3524:26-36 "在 'react-redux' 中找不到导出 'default' (导入为 'reactRedux')

我尝试过使用globalsnamedExports。我还没有找到一种方法让 redux-form 成为我项目的同行。

【问题讨论】:

  • Instead of import myModule from 'my-module'; try using import myModule from 'node_modules/my-module/dist/my-module.js'. github.com/rollup/rollup-plugin-commonjs/issues/206
  • 我终于解决了,我不得不用redux-form/immutable 设置我的外部,而不仅仅是redux-form

标签: reactjs redux react-redux redux-form rollup


【解决方案1】:

我终于解决了,我不得不用redux-form/immutable 设置我的外部,而不仅仅是redux-form

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-18
    • 2020-07-05
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    相关资源
    最近更新 更多