简体   繁体   中英

use awayjs from npm repository

I really interest in developing games and data visualization projects with awayjs library, but I can't orginize well my workflow to start using it.

First of all I made the standart workflow with gulp, npm node_modules and so on. It's okey build, bundle and browserSync greeter example.

Then I install awayjs library from npm repository:

npm install awayjs-full --save dev

NPM includes awayjs-full library in node_modules local repository. And now I have ability to use all awayjs typescript classes for develop applications:

// main.ts
import * as awayjs from "awayjs-full";

class Away3D {

   private _view: awayjs.View;
   constructor() {
       this.init();
   }

   private init(): void {
       this.initEngine();
   };

   private initEngine(): void {
       this._view = new awayjs.View(new awayjs.DefaultRenderer());
   }
};
window.onload = function () {
     new Away3D();
}

Typescript see every class and let use it in source code. But when I try to bundle javascript compiled code, the bundle gulp task through error: 'can not find module "awayjs-full"', that means that .js compiled file cannot require this library even if it store in npm repository. What I should do to let javascript finally require this lib ?!

That was the problem for me, because I didn't exactly understand from where generated javascript code require the javascript dependencies. I thought I use npm node modules for working in development enviroment and bower for runtime, but in this case all functions even the bundle gulp task use the same npm reposity. So if you have same problems first of all check npm repository of requiring module, look at the package.json and be sure that it has a correct link on main js library. In my case there was a index.js setting in root of repository whick exactly didn't exist. That was I got problem with requiring awayjs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM