Coder Social home page Coder Social logo

ruj89 / electron-typescript-native Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 2.0 562 KB

A native Electron module using Typescript

License: MIT License

TypeScript 72.19% JavaScript 12.86% Python 2.68% C++ 12.26%
electron typescript native-javascript c-plus-plus javascript boilerplate node-gyp windows

electron-typescript-native's Introduction

A native Electron module using Typescript

Summary

Install and run on Windows

Install NodeJS, Microsoft Visual Studio Build Tools 17 and Python 2.7.

After that, launch CMD.exe, enter in the project folder and launch

cd native_module && npm install && npm run build
cd .. && cd electron_sample && npm install && npm run build
npm run start

After the start task, the native string world will appear inside the DOM of an Electron window.

Documentation

The application is split in two parts:

  • electron_sample: a sample application running in Electron using a Typescript Webpack bundled renderer.
  • native_module: a sample Typescript module that integrates a native feature.

In order to display the sample string generated by the module in the Electron application, we need to inject it into the application itself.

electron_sample application

The application main treat is to generate an Electron application and to include the native_module.

The assets file are already moved in the dist folder and webpack is configured to build the bundle inside that folder.

The application package.json just includes the local path in his dependencies.

"dependencies": {
    "native_module": "file:../native_module"
}

devDependencies are included to compile and run correctly the application.

In our scripts we have:

  • start task, to launch the application.
  • build task, to compile and pack Typescript and Javascript files.

native_module module

First of all, let's consider the tsconfig.json file. Using:

"declaration": true,
"outDir": "dist"

the Typescript compiler will use dist as the build directory and will generate declarations.

In the package.json

"main": "dist/index.js",
"types": "dist/index.d.ts"

indicates the correct path for the main file and typing declarations.

The scripts used in this module are

"build": "tsc",
"build-native": "node-gyp rebuild"
  • build-native: compiles the C++ code.
  • build: compiles the ts code.

In order to develop using a native library, we need node-gyp. @types/node and typescript are useful to compile Typescript.

"devDependencies": {
    "@types/node": "^20.6.3",
    "node-gyp": "^9.4.0",
    "typescript": "^5.2.2"
}

In Typescript index.ts is wrapped the exported hello function used in the Electron application.

electron-typescript-native's People

Contributors

dependabot[bot] avatar ruj89 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.