Developing a webpage similar to keycode.info and serving it in a Docker Container

Developing a webpage similar to keycode.info and serving it in a Docker Container

Original article and the source code of the project published at Madrid repo on my GitHub account (polatengin).

Not : Makalenin Türk?e halini de Madrid repo i?erisinde bulabilirsiniz ??

You can find and use the running version of this project at https://polatengin-madrid.netlify.com/

The reason I made this project;

  • To learn how to inject javascript and css into an html page by configuring Webpack and PostCSS
  • Experience and understand how browsers are processing keyboard events
  • Create and run a pipeline with GitHub Actions
  • Gain the habit of project development within Visual Studio Code DevContainer

Technologies I used in this project are;

  • Typescript
  • WebPack
  • PostCSS
  • GitHub Actions
  • Docker
  • Netlify
  • DevContainers

To create the project, let's run the following command in an empty directory

npm init --force

Now, open a Terminal window and run the following command to add the keycode npm package to package.json

npm i keycode --save

Now, we can require the keycode module in src/index.ts

const keycode = require('keycode');

By attaching to the keydown event of the window global object, we can capture all the pressed keys in the entire browser window.

window.addEventListener('keydown', (e) => {
});

By calling the stopPropagation() and preventDefault() methods in the event handler, we prevent the keys from being processed by the browser.

So, even if the keys like F5, F12 are pressed, the browser will not process them.

We add the required html code into the src/index.html file so that a table will appear on the screen.

Also, we're providing the same editor settings to the developers (space/tabend-of-line-character, etc.) with the .editorconfigfile.

In the tsconfig.json file, we give the compilerOptions.outDir property value of ./dist, so that when the webpack compiles, the compiled files will be created in the ./dist folder.

In the src/index.ts file, we capture all keydown events via the window.addEventListener() method.

We use the following two lines to prevent any keydown events we capture from being captured by the browser.

e.stopPropagation();
e.preventDefault();

We added the following plugins into the webpack.config.js file

Also, with the hash option of the HtmlWebpackPlugin plugin, we added the compiled ts files into the index.html as bundle.js?{HASH}.

Thanks to Multi-Layered Dockerfile, we compile the project in node:12.11.1 image, then move all compiled files to nginx:1.17.0-alpine image and expose them.

At the end, we have a Docker Image that takes about 20MB in size.

No alt text provided for this image


???? Dani Gámez Franco

Top 1.5% at StackOverflow | Lead Web3 Full-Stack Software Engineer | JS, TS, React, Next.js, Node.js, tRPC, DynamoDB, Clean Software Architecture

4 年

Looks nice, I have actually just released a similar site with a few more options and soon mobile support and cross-browser compatibility information (particularly for IE and Safari): https://keyjs.dev/

Vitor Azevedo

Senior Frontend Developer

5 年

This ia great! Congrats

要查看或添加评论,请登录

Engin Polat的更多文章

  • Run Jenkins on Azure Container Instances

    Run Jenkins on Azure Container Instances

    Original article and the source code of the project published at Amsterdam repo on my GitHub account (polatengin). With…

  • Developing an SSH Configuration Helper with PowerShell

    Developing an SSH Configuration Helper with PowerShell

    Original article and the source code of the SSH Configuration PowerShell Script published at Kiev repo on my GitHub…

  • Documentation Conventions

    Documentation Conventions

    Original article published at Project Standards repo on my GitHub account (polatengin), you can find it on…

  • Bash Scripting Conventions

    Bash Scripting Conventions

    Original article published at Project Standards repo on my GitHub account (polatengin), you can find it on Bash…

    1 条评论

社区洞察

其他会员也浏览了