Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.

Add support for target: 'node'? #365

@cskeppstedt

Description

@cskeppstedt

In my continuous efforts of applying Sagui to any javascript development problem that pops up, I've now found a use case that may be interesting.

I'm building a small side project, with the backend built on serverless (AWS Lambda). The frontend is built with Sagui as usual.

My plan was to have 2 separate folders (I think a shared sagui.config.js would be too complex), and have 1 shared directory flow-lib where I can put type definitions that would be shared between the 2 projects. This to have static type checking for the API calls between front- and backend. This means that both front- and backend will contain flow type definitions, and reference the shared type definitions.

AWS Lambda does not speak flow-types. It only speaks node 6.10+. So, I wanted to look into the possibility of Sagui building with target: 'node' (and libraryTarget 'commonjs2'). I tried building the backend as a "library", which works but obviously generates a lot of nonsense in terms of webpack-preamble in the top of the output. My motivation for using Sagui also for the backend, is that most of the Sagui tools are useful there as well (linting/prettier, stripping flow-types, minification, etc).

This is the conceptual project structure, where backend/src may contain a number of files (function1.js, function2.js) that will be transpiled to backend/dist and then uploaded to AWS Lambda:

.
├── flow-lib
│   └── shared-types.js
├── frontend
│   ├── dist
│   ├── node_modules
│   ├── package.json
│   ├── sagui.config.js
│   ├── src
│   └── yarn.lock
└── backend
    ├── dist
    ├── node_modules
    ├── package.json
    ├── sagui.config.js
    ├── serverless.yml
    ├── src
    └── yarn.lock

I'm still not entirely sure what target: 'node' would entail for the rest of the sagui-tasks (like test for instance), I've only pondered a little bit on build and dist.

TL;DR: supporting target: 'node', good/bad/idk? I can try and hack together a POC if you'd be interested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions