Use components from two versions of the same library (npm / Material UI in my case)

血红的双手。 提交于 2019-11-28 23:55:43

After some googling, found this. To use both versions:

yarn add material-ui@latest
yarn add material-ui-next@npm:material-ui@next

Then you can use

import Divider from 'material-ui-next/Divider'

or

import Divider from 'material-ui/Divider'

I created in /packages a folder called material-ui-next with only a package.json inside it which contains :

{
  "name": "material-ui-next",
  "version": "1.0.0",
  "scripts": {
    "postinstall": "mv node_modules/material-ui/* ."
  },
  "dependencies": {
    "material-ui": "next"
  }
}

So now from the root of the project one can do npm install packages/material-ui-next --save then one can createPalette = require('material-ui-next/styles/palette') or whatever one wants to require from material-ui now aliased as material-ui-next.

Explanations : as "material-ui": "next" is a dependency it's will be installed in node_modules/material-ui so by adding a script after the package material-ui-next is installed to move node_modules/material-ui to the root of the package we can require('material-ui-next/WHATEVER')

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!