在Angular + Electron构建的应用程序中导入自定义TS模块时出错

时间:2018-09-18 07:32:03

标签: angular typescript electron angular6 electron-builder

我在Angular 6 / Electron 2应用程序上工作(基于此repo),并且在构建的应用程序上出现错误(开发中一切正常)。

当我想使用 import 方法在主Electron文件(main.ts文件)中导入自定义TS文件时出现错误。它可以在开发中使用,但是当我要构建应用程序时,所构建的应用程序在启动时会引发错误。

由于配置文件中的错误,我认为在构建的应用程序中文件路径已严重解决,但是我找不到解决方案。

我要启动已构建的应用程序时出错:

Error: Cannot find module './src/ipc.el.service'

main.ts中的导入行:

import { ElectronIPCService } from './src/ipc.el.service';

使用的版本:

@angular/compiler :               6.1.2
@angular/compiler-cli :           6.1.2
@angular/core :                   6.1.2
@angular-devkit/architect         0.8.2
@angular-devkit/build-angular     0.8.2
@angular-devkit/build-optimizer   0.8.2
@angular-devkit/build-webpack     0.8.2
@angular-devkit/core              0.8.2
@angular-devkit/schematics        0.8.2
@angular/cli                      6.2.2
@ngtools/webpack                  6.2.2
@schematics/angular               0.8.2
@schematics/update                0.8.2
rxjs                              6.2.2
typescript                        2.9.2
webpack                           4.19.0
electron                          2.0.8
electron-builder                  20.28.4

electron-builder.json文件:

{
    "productName": "MyProject",
    "appId": "myproject",
    "extraResources": ["./src/assets/**/*"],
    "publish": [{
        "provider": "generic",
        "url": "https://updates.rocketnav.com/"
    }],
    "npmRebuild": false,
    "nodeGypRebuild": false,
    "directories": {
        "output": "release/"
    },
    "files": [
        "**/*",
        "!*.ts",
        "!*.code-workspace",
        "!LICENSE.md",
        "!package.json",
        "!package-lock.json",
        "!src/",
        "!e2e/",
        "!hooks/",
        "!.angular-cli.json",
        "!_config.yml",
        "!karma.conf.js",
        "!tsconfig.json",
        "!tslint.json"
    ],
    "win": {
        "icon": "dist/icon",
        "artifactName": "${productName}-installer.${ext}",
        "target": [
            "nsis"
        ]
    },
    "mac": {
        "category": "Entertainment",
        "icon": "dist/icon",
        "target": [
            "dmg",
            "pkg",
            "zip"
        ]
    },
    "dmg": {
        "artifactName": "${productName}-installer.${ext}",
        "contents": [{
                "x": 110,
                "y": 175
            },
            {
                "x": 400,
                "y": 175,
                "type": "link",
                "path": "/Applications"
            }
        ]
    },
    "linux": {
        "artifactName": "${productName}-installer.${ext}",
        "target": [
            "AppImage",
            "deb",
            "rpm"
        ],
        "icon": "build/",
        "category": "Network"
    },
    "nsis": {
        "deleteAppDataOnUninstall": true
    }
}

tsconfig.json文件:

{
    "compileOnSave": false,
    "compilerOptions": {
        "outDir": "./dist/out-tsc",
        "baseUrl": "src",
        "sourceMap": true,
        "declaration": false,
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "allowJs": false,
        "target": "es6",
        "typeRoots": [
            "node_modules/@types"
        ],
        "lib": [
            "es2017",
            "dom"
        ]
    },
    "include": [
        "main.ts",
        "src/**/*"
    ],
    "exclude": [
        "node_modules"
    ]
}

angular.json文件的一部分:

"MyProject": {
    "root": "",
    "sourceRoot": "src",
    "projectType": "application",
    "architect": {
        "build": {
            "builder": "@angular-devkit/build-angular:browser",
            "options": {
                "outputPath": "dist",
                "index": "src/index.html",
                "main": "src/main.ts",
                "tsConfig": "src/tsconfig.app.json",
                "polyfills": "src/polyfills.ts",
                "assets": [
                    "src/assets",
                    "src/background.html"
                ],
                "styles": [
                    "./src/styles.scss",
                    "./node_modules/bootstrap/dist/css/bootstrap.min.css"
                ],
                "scripts": [
                    "src/ipc.el.service.js"
                ]
            },
            "configurations": {
                "dev": {
                    "optimization": false,
                    "outputHashing": "all",
                    "sourceMap": true,
                    "extractCss": true,
                    "namedChunks": false,
                    "aot": false,
                    "extractLicenses": true,
                    "vendorChunk": false,
                    "buildOptimizer": false,
                    "fileReplacements": [{
                        "replace": "src/environments/environment.ts",
                        "with": "src/environments/environment.dev.ts"
                    }]
                },
                "production": {
                    "optimization": true,
                    "outputHashing": "all",
                    "sourceMap": false,
                    "extractCss": true,
                    "namedChunks": false,
                    "aot": true,
                    "extractLicenses": true,
                    "vendorChunk": false,
                    "buildOptimizer": true,
                    "fileReplacements": [{
                        "replace": "src/environments/environment.ts",
                        "with": "src/environments/environment.prod.ts"
                    }]
                }
            }
        },

感谢您的帮助!

0 个答案:

没有答案