Karmello
Karmello

Reputation: 61

Is it bad Webpack practice to import all libraries that React app needs into one file?

Is it bad Webpack practice to import all the libraries that React application needs in one place, for example inside Libs.js, and then inside every application module get them all with just one import statement ?

Libs.js

import React from 'react';
import { PropTypes } from 'prop-types';
import { connect } from 'react-redux';
import { reduxForm, Field, getFormValues, change } from 'redux-form';
import isNull from 'lodash/isNull';


export default {
  React: React,
  PropTypes: PropTypes,
  redux: {
    connect: connect
  },
  form: {
    create: reduxForm,
    change: change,
    getValues: getFormValues,
    Field: Field
  },
  lodash: {
    isNull: isNull
  }
};

Any app module

import libs from 'common/libs';

Upvotes: 0

Views: 409

Answers (1)

Vlad Nicula
Vlad Nicula

Reputation: 3696

Webpack and rollup don't need this kind of enclosed module that groups together all libraries. If you are using a bundling system and import react 20 times, the system will not to import and include the code only once, so it's easier to just import what library dependencies you have in the files where they are used.

With this approach you also get more clarity of what libraries are used by which components.

Short answer: Yes, in my opinion, it is a bad practice and I wouldn't do it in any project.

Upvotes: 1

Related Questions