Electron-forge: How to use @aliases to get reference to another modules?

Created on 12 Jun 2019  路  3Comments  路  Source: electron-userland/electron-forge

This is only a question, not a bug. I work with angular and electron-forge https://github.com/kzimny/electron-typescript-sqlite3-typeorm. How to use aliases to import modules in electron-forge?

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';

import { ViewerModule } from '@viewer/viewer.module'; <<<<<<<<<<<<<<<<<<ALIAS
import { AppComponent } from './app.component';

@NgModule({
    imports: [
        BrowserModule,
        ViewerModule,
        RouterModule.forRoot([])
    ],
    declarations: [ AppComponent ],
    bootstrap: [ AppComponent ]
})
export class AppModule {}

Aliases in angular are usually added to tsconfig.json file:

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

But this doesn't work in electron-forge. Also when I add the alias to .compiler file as follow:

{
    "env": {
        "development": {
            "text/typescript": {
                "removeComments": false,
                "preserveConstEnums": true,
                "declaration": true,
                "noImplicitAny": true,
                "noImplicitReturns": true,
                "suppressImplicitAnyIndexErrors": true,
                "strictNullChecks": true,
                "noUnusedLocals": true,
                "noImplicitThis": true,
                "noUnusedParameters": true,
                "inlineSourceMap": true,
                "inlineSources": true,
                "importHelpers": true,
                "noEmitHelpers": true,
                "experimentalDecorators": true,
                "target": "es2015",
                "module": "commonjs",
                "emitDecoratorMetadata": true
            }
        },
        "production": {
            "text/typescript": {
                "removeComments": false,
                "preserveConstEnums": true,
                "declaration": true,
                "noImplicitAny": true,
                "noImplicitReturns": true,
                "suppressImplicitAnyIndexErrors": true,
                "strictNullChecks": true,
                "noUnusedLocals": true,
                "noImplicitThis": true,
                "noUnusedParameters": true,
                "sourceMap": false,
                "importHelpers": true,
                "noEmitHelpers": true,
                "experimentalDecorators": true,
                "target": "es2015",
                "module": "commonjs",
                "emitDecoratorMetadata": true
            }
        },
        "paths": {
            "@viewer/*": [ <<<<<<<<<<<<<<<<<<<<<<<<<<<<ALIAS
                "viewer/*"
            ]
        }
    }
}

Any suggestion?

Question

Most helpful comment

All 3 comments

At this point in time, I would suggest migrating to Electron Forge v6 and using the webpack plugin instead of the electron-compile ecosystem.

Thx! How to install version 6.0.0? The latest available is version 5.2.4 https://www.npmjs.com/package/electron-forge No documentation found how to install v6.0.0 or upgrade to v.6.0.0. Thank you.

Was this page helpful?
0 / 5 - 0 ratings