Can we use npm packages in cocos-creator?

2.9k views Asked by At

I would like to use npm packages like moment, lodash, axios etc. in cocos creator.

Is it possible to use them via npm i --package-name?

Are there any restrictions to use them in cocos? I couldn't find any information in cocos docs, if there is any information that you know how cocos approach to npm packages please share a link or give information about their vision.

2

There are 2 answers

0
Manthan Togadiya On

You can open cocos-creator project like any other project in any code editor from where you can manage your dependencies.

From what I understand you just need to do the following:

  1. npm init in root creator-project directory.
  2. Install packages you want to use.
  3. Use require on any cocos-creator script.
1
Thanh Quoc On

Yes, You can install node packages.

npm location

Then, use import or require

import package