1

我有一个应用程序,我试图将其转换为使用 angular cli (v7)。该应用程序处于正常工作状态。

该应用程序由 2 个站点和一个公共库组成:

- ui-site-1
- ui-site-2
- ui-lib

我正在使用 ng build 来构建和打包 UI-lib,但在指向 public_api.ts 的 FESM2015 阶段存在错误:

public_api.ts:

// Lots of exports...
export { setup } from './core/connect/setup'; <-- Falls over if including this.

连接/setup.js

function setup(p1, p2, p3) {
// Some code
}


function method12(p1, p2, p3) {
// Some code
}

export { setup };

错误:

Could no resolve './setup' from ui-lib/dist/esm2015/core/setup.js

注意:如果我将文件转换为 .ts,ng build 运行良好并创建了一个 dist 文件夹。但是,在 setup.js 中,我引入了许多其他 .js 文件,因此现在无法将所有这些文件转换为 .ts 并解决类型问题

更新:

tsconfig.json

{
    "compileOnSave": false,
    "compilerOptions": {
        "baseUrl": "./",
        "outDir": "./dist/out-tsc",
        "sourceMap": true,
        "declaration": false,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "importHelpers": true,
        "target": "es5",
        "typeRoots": [
            "node_modules/@types"
        ],
        "lib": [
            "es2017",
            "dom"
        ],
        "paths": {
            "my-lib": [
                "dist/my-lib"
            ],
            "my-lib/*": [
                "dist/my-lib/*"
            ]
        }
    }
}

tsconfig.lib.json:

{
    "extends": "../tsconfig.json",
    "compilerOptions": {
        "outDir": "../../out-tsc/lib",
        "target": "es2015",
        "module": "es2015",
        "moduleResolution": "node",
        "declaration": true,
        "sourceMap": true,
        "inlineSources": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "importHelpers": true,
        "types": []
    },
    "angularCompilerOptions": {
        "annotateForClosureCompiler": false,
        "skipTemplateCodegen": true,
        "strictMetadataEmit": false,
        "fullTemplateTypeCheck": true,
        "strictInjectionParameters": true,
        "enableResourceInlining": true
    },
    "exclude": [
        "src/test.ts",
        "**/*.spec.ts"
    ],
    "include": [
        "src/**/*",
        "./src/**/*",
    ]
}
4

1 回答 1

1

connect/setup.js 应该是:

export function setup(p1, p2, p3) {
// Some code
}


function method12(p1, p2, p3) {
// Some code
}
于 2019-08-05T09:49:42.877 回答