faceyspacey / redux-first-router-demo

Kick-Ass Universal RFR Demo That Answers Your SSR + Splitting Questions
MIT License
126 stars 46 forks source link

[Question] Make build:node more robust #23

Closed Maushundb closed 7 years ago

Maushundb commented 7 years ago

Hey spacey, it seems like in your package.json, you manually transpile all the dependencies of index.js:

build:node": "cross-env NODE_ENV=production babel server/index.js -o buildServer/index.js && babel server/api.js -o buildServer/api.js",

Given that you use api.js in setting up your server.

I might just be a WebPack noob, but it there a proper way to set up this script to compile an arbitrary dependency graph used by your node server? I ask because I am trying to set up an endpoint that queries a database, which has it's own intricate dependency graph. For example, this script errors when I try adding the following in server/index.js:

import db from './db/models';

//command line error

> App@0.0.1 serve /Users/maushundb/Code/myApp
> cross-env NODE_ENV=production node buildServer/index.js

module.js:487
    throw err;
    ^

Error: Cannot find module './db/models'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/maushundb/Code/myApp/buildServer/index.js:37:15)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)

Thanks dude!

faceyspacey commented 7 years ago

that's not webpack. it's babel transpiling the bootstrap code. it also just happens to have the api.

use this instead:

https://babeljs.io/docs/usage/cli/#babel-compile-directories

faceyspacey commented 7 years ago

it should be this:

"build:node": "cross-env NODE_ENV=production babel server -d buildServer --ignore configureStore,render",

feel free to PR