用react-scripts-ts编译并定义webpack外部

时间:2019-04-12 14:59:02

标签: javascript node.js reactjs typescript webpack

我创建了一个基本的React应用程序,并从npm中添加了Azure Devops的VSS SDK。

这基本上是一个SDK脚本,我将其复制并作为脚本包含在HTML中。

该软件包也有一些类型供开发。

当我在开发中使用这些类型时,它们工作正常。但是,当我想用​​react-scripts-ts构建编译我的代码时,Webpack试图将这些依赖项包含在其捆绑包中并提供给我:

未找到模块:错误:无法解析'e:\\ src \ modules \ App'中的'VSS / Controls

如果我导航到node_modules / react-scripts-ts / config / webpack.prod.config,则可以将这些命名空间添加为外部名称,并且可以正常工作,但是我不想在node_module下修改构建脚本(有点黑)。

有没有办法告诉react的构建脚本忽略这些模块?

这是我的package.json:

{
  "name": "dcp",
  "version": "0.1.0",
  "private": true,
  "homepage": ".",
  "dependencies": {
    "office-ui-fabric-react": "^6.165.1",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-scripts-ts": "3.1.0",
    "vss-web-extension-sdk": "^4.126.2"
  },
  "scripts": {
    "start": "react-scripts-ts start",
    "build": "react-scripts-ts build && tfx extension create",
    "test": "react-scripts-ts test --env=jsdom",
    "eject": "react-scripts-ts eject"
  },
  "devDependencies": {
    "@types/jest": "^22.2.3",
    "@types/node": "^11.13.4",
    "@types/react": "^16.8.13",
    "@types/react-dom": "^16.8.3",
    "typescript": "^2.8.4"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "outDir": "build/dist",
    "module": "amd",
    "lib": ["es6", "dom"],
    "sourceMap": true,
    "allowJs": true,
    "jsx": "react",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "importHelpers": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "types": [
      "vss-web-extension-sdk",
      "jest"
    ]
  },
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "src/setupTests.ts"
  ]
}

我正在尝试这样导入它:

import { Control } from "VSS/Controls";

0 个答案:

没有答案