GithubHelp home page GithubHelp logo

matthawkins90 / withdecred.org Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pavel-lens/withdecred.org

0.0 0.0 1.0 12.78 MB

Dockerfile 0.42% Vue 73.88% JavaScript 7.75% TypeScript 3.18% SCSS 14.78%

withdecred.org's Introduction

nuxtjs-express-typescript

Nuxt.js

  • Components with Typescript
  • Express server with Typescript

Recommended VScode extensions

  • Javascript support installed
  • Vetur extension
  • vue syntax highlighting
  • prettier with "Format on Save" option

Build Setup

# install dependencies
$ npm install

# serve with hot reload at localhost:3000
$ npm run dev

# build for production and launch server
$ npm run build
$ npm run start

# generate static project
$ npm run generate

For detailed explanation on how things work, check out Nuxt.js docs.

Tests

Running frontend and backend tests are separated with following scripts.

# run frontend tests
$ npm run test:client
# run frontend tests in watch mode
$ npm run test:client:watch

# run backend tests
$ npm run test:server
# run backend tests in watch mode
$ npm run test:server:watch

Docker

Build docker image from current directory.

$ docker build -t nuxt_typescript_app .

Now run the docker image and expose local port 3000.

$ docker run -it -p 3000:3000 nuxt_typescript_app

The application should be accessible at http://0.0.0.0:3000

Try to reach baceknd API at http://0.0.0.0:3000/api/users/

Typescript in Vue components

components/User.vue

This is a Vue.extend({}) syntax and in my opinion provides a bit better Typescript safety-net.

It also comes from the well-known Options API.

components/User2.vue

This is a class-based component with annotations and native getter class methods.

However, the big limitation is that when declaring a class variable for mutating state (OptionAPI data() { ... }), you always have to initialize it with some value. You cannot leave it uninitialized and also you can't assign undefined as initialization value, because it will NOT be reactive (Vue will not work as expected).

Also, if you want to initialize your state based on props, you have to use the data() { ... } function anyway.

How Typescript is compiled and how app is served in production

To understand how things work in production, we have to look at two components of the app:

  • NuxtJS part
  • ExpressJS backend API

NuxtJS

NuxtJS is compiled into .nuxt/dist/ directory which contains client/ and server/ directory.

In the client/ directory, you will find Javascript bundles compiled by Webpack, separated into several chunks. You will also find statics assets like fonts/.

The server directory contains a server.js file which basically handles serving of static files and other Nuxt-related middleware functions. This is wired by app.use(nuxt.render) in original <root>server/index.ts file.

ExpressJS backend API

The Express API implemented in <root>/server/ directory is compiled by Typescript compiler and saved into <root>/server-dist/ folder.

If you look at start script in package.json file, you will see the following node server-dist/index.js.

That means that in production, there is a node server running a compiled version of original server/index.ts, but now it's compiled to server-dist/index.js.

withdecred.org's People

Contributors

dcr-el-capitan avatar pavel-lens avatar richardred0x avatar matthawkins90 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.