-
Notifications
You must be signed in to change notification settings - Fork 32
Add support for target: 'node'? #365
Description
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.