zl程序教程

您现在的位置是:首页 >  其它

当前栏目

[Yarn] Use Yarn to Create an Alternative Import Name of an Installed Library

to of name an create use import library
2023-09-14 09:00:51 时间

In this lesson we'll show how to use yarn to alias the names of same npm libraries but install different versions. This could allow for easy migrating from one library version to an upgraded version.

 

You can install lib by using Yarn and give the lib an alias name:

yarn add lodash3@npm:lodash^3  // install lodash version 3
yarn add lodash4@npm:lodash^4  // install lodash version 4 

 

Then you can use it:

import lodash3 from 'lodash3';
import lodash4 from 'lodash4';

 

Note: it only works when you and your team use Yarn, npm won't work.