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

Add support for target: 'node'? #365

Open
cskeppstedt opened this issue Jun 8, 2017 · 3 comments
Open

Add support for target: 'node'? #365

cskeppstedt opened this issue Jun 8, 2017 · 3 comments

Comments

@cskeppstedt
Copy link

cskeppstedt commented Jun 8, 2017

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.

@cskeppstedt cskeppstedt changed the title Support for target: 'node' Add support for target: 'node'? Jun 8, 2017
@cskeppstedt cskeppstedt changed the title Add support for target: 'node'? Add support for target: 'node'? Jun 8, 2017
@xaviervia
Copy link
Member

Well, given that we are seriously considering adding Jest alongside Karma in v10, that would be a solution for the testing problem. And in general, I have indeed been using Sagui for more than just frontend projects, so I understand the motivation.

Although, as you point out, I don’t know exactly what it would entail, I think targeting node makes sense.

@xaviervia
Copy link
Member

xaviervia commented Jun 9, 2017

Quick list of things Sagui-for-node could do:

  • Compile JS with the same Babel configuration (this would have to be added since now it's only done through Webpack)
  • Of course prettier/lint/flow (these are not related to webpack after all)
  • Switch to Jest (or, if we add Jest in general, disable Karma) for the running of the tests.

Don’t know if Webpack has a "target: node" option, which is a possibility.

@cskeppstedt
Copy link
Author

Don’t know if Webpack has a "target: node" option, which is a possibility.

It should, there's an example in the docs. According to this example, the possible targets are ['web', 'webworker', 'node', 'async-node', 'node-webkit', 'electron-main'].

And yeah, using jest would be awesome. I used it on a nodejs project recently and it's just a breeze to do TDD with it :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants