整合JointJS

时间:2017-05-01 14:28:10

标签: angular jointjs

我跟着How can I use JointJS with an application built with Angular CLI?在Angular上安装了JointJS。无论如何,当我启动项目时,我遇到了这个问题:

Module not found: Error: Can't resolve './node_modules/jointjs/dist/joint.js'

我尝试更改此导入

const joint = require('./node_modules/jointjs/dist/joint.js'); 

import * as joint from 'jointjs/dist/joint';

这样我启动项目时没有问题,但我不能使用这种方法let m1 = new joint.shapes.devs.Model因为我有这个错误:

TS2339:Property 'devs' does not exist on type 'typeof shapes'

使用这样的方法:let rect2 = new joint.shapes.basic.Rect或此let link = new joint.dia.Link我没有问题。我认为那是一个进口问题。

这是我的angular-cli.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "version": "1.0.0-beta.32.3",
    "name": "jointangular"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.json",
      "prefix": "app",
      "styles": [
        "styles.css",
        "../node_modules/jointjs/css/layout.css"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/jointjs/dist/joint.js"

      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "files": "src/**/*.ts",
      "project": "src/tsconfig.json"
    },
    {
      "files": "e2e/**/*.ts",
      "project": "e2e/tsconfig.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

我的package.json:

{
  "name": "jointangular",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^2.4.0",
    "@angular/compiler": "^2.4.0",
    "@angular/core": "^2.4.0",
    "@angular/forms": "^2.4.0",
    "@angular/http": "^2.4.0",
    "@angular/platform-browser": "^2.4.0",
    "@angular/platform-browser-dynamic": "^2.4.0",
    "@angular/router": "^3.4.0",
    "@types/jquery": "^2.0.40",
    "core-js": "^2.4.1",
    "jointjs": "^1.0.3",
    "jquery": "^3.1.1",
    "rxjs": "^5.1.0",
    "zone.js": "^0.7.6"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0-beta.32.3",
    "@angular/compiler-cli": "^2.4.0",
    "@types/backbone": "^1.3.33",
    "@types/jasmine": "2.5.38",
    "@types/jointjs": "^1.0.3",
    "@types/lodash": "^3.10.1",
    "@types/node": "~6.0.60",
    "backbone": "^1.3.3",
    "codelyzer": "~2.0.0-beta.4",
    "install": "^0.8.9",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.0.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "lodash": "^3.10.1",
    "npm": "^4.5.0",
    "protractor": "~5.1.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.4.2",
    "typescript": "~2.0.0"
  }
}

你有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我相信您需要在"dependencies"中安装中枢和lodash,因为joint.js需要它们。

不仅开发需要它们("dev-dependencies")。这就是为什么它崩溃了