更改从节点包导出的React组件的默认渲染

时间:2018-09-09 15:58:00

标签: reactjs node-modules rollupjs

我创建了一个程序包,用于导出反应组件。为了生成程序包,我使用了汇总。

现在在以下情况下,ParentComponent渲染ChildComponent,但是有什么方法可以覆盖其默认渲染?

const ChildComponent = () => {
    return <div>Hello</div>;
};

const ParentComponent = () => {
    return <ChildComponent />;
}
  

rollup.js

import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import { uglify } from 'rollup-plugin-uglify';
import replace from 'rollup-plugin-replace';
import json from 'rollup-plugin-json';

import copyFiles from "./rollup.copyfiles.plugin.js"

var config = {
  input: 'src/entry.js',
  external: ['react', 'prop-types', 'mobx', 'mobx-react', 'react-router', 'react-router-dom', 'arv-reactcomponents', 'react-recaptcha-google', 'isomorphic-fetch', 'react-native-uuid', 'es6-promise'],
  output: [{
    file: 'bundle/cjs/main.js',
    format: 'cjs',
    sourcemap: true
  }],
  plugins: [
    json(),
    resolve({
      jsnext: true,
      main: true,
    }),
    commonjs({
      include: 'node_modules/**'
    }),
    babel({
      babelrc: false,
      exclude: 'node_modules/**',
      "plugins": [
        "transform-runtime",
        "transform-decorators-legacy"
      ],
      "presets": [
        ["env", {
          "modules": false
        }],
        "es2017",
        "stage-0",
        "react"
      ],
      "runtimeHelpers": true
    }),
    replace({
      'process.env.NODE_ENV': JSON.stringify('production')
    }),
    copyFiles({
      input: 'src/component',
      output: 'bundle/component',
      matches: /.*\.scss$/
    }),
    copyFiles({
      input: 'src/mixins',
      output: 'bundle/mixins',
      matches: /.*\.scss$/
    })
  ]
}

export default config;

0 个答案:

没有答案