Y
Y
yankoyski2019-02-25 13:16:58
JavaScript
yankoyski, 2019-02-25 13:16:58

Where to store common react components and how to include them?

The project has common components, connecting them via relative links: "../../../" is inconvenient.
Are there alternatives?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
NaN, 2019-02-25
@KornevaViktoria

ну можно как вариант рассмотреть вынесение общих компонент в отдельный репозиторий и подключение его как npm пакет. Ну или да, как пишут выше, если дело только в путях

Николай Демидовец, 2019-02-25
@Nik_o_lay

https://webpack.js.org/configuration/resolve/
+
https://github.com/timarney/react-app-rewired#how-...
+
https://www.npmjs.com/package/react -app-rewire-aliases
+ config-overrides.js
file (in the same place as package.json)

const rewireAliases = require("react-app-rewire-aliases");
const { paths } = require("react-app-rewired");
const path = require("path");

module.exports = function override(config, env) {
  config = rewireAliases.aliasesOptions({
    Views: path.resolve(__dirname, `${paths.appSrc}/templates/default/views`),
    Components: path.resolve(__dirname, `${paths.appSrc}/controllers`),
    Store: path.resolve(__dirname, `${paths.appSrc}/controllers/store`),
    Config: path.resolve(
      __dirname,
      `${paths.appSrc}/controllers/services/Config`
    ),
  })(config, env);

  return config;
};

=
5c7400acb1f2a974987741.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question